Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing app.js: "ImportDeclaration should appear when the mode is ES6 and in the module context." #56

Closed
vollkorn1982 opened this issue Sep 10, 2019 · 11 comments
Assignees
Labels

Comments

@vollkorn1982
Copy link

Describe the bug
When analysing an electron app I receive a parsing error message from eslint. Unfortunately this is an electron app I am not allowed to share.

To Reproduce
Steps to reproduce the behavior:

  1. $ electronegativity -i .
▄▄▄ ▄▄▌ ▄▄▄ .▄▄·▄▄▄▄▄▄▄               
▀▄.▀██• ▀▄.▀▐█ ▌•██ ▀▄ █▪             
▐▀▀▪██▪ ▐▀▀▪██ ▄▄▐█.▐▀▀▄ ▄█▀▄         
▐█▄▄▐█▌▐▐█▄▄▐███▌▐█▌▐█•█▐█▌.▐▌        
 ▀▀▀.▀▀▀ ▀▀▀·▀▀▀ ▀▀▀.▀  ▀▀█▄▀▪        
 ▐ ▄▄▄▄ .▄▄ • ▄▄▄▄▄▄▄▪  ▌ ▐▪▄▄▄▄▄▄· ▄▌
•█▌▐▀▄.▀▐█ ▀ ▐█ ▀•██ ██▪█·██•██ ▐█▪██▌
▐█▐▐▐▀▀▪▄█ ▀█▄█▀▀█▐█.▐█▐█▐█▐█▐█.▐█▌▐█▪
██▐█▐█▄▄▐█▄▪▐▐█ ▪▐▐█▌▐█▌███▐█▐█▌·▐█▀·.
▀▀ █▪▀▀▀·▀▀▀▀ ▀  ▀▀▀▀▀▀. ▀ ▀▀▀▀▀  ▀ •
     v1.3.2  https://doyensec.com/

Scan Status:
40 check(s) successfully loaded: 5 global, 35 atomic
████████████████████████████████████████ 100% | 18/18
Error parsing <redacted>/resources/app/src/app.js - ImportDeclaration should appear when the mode is ES6 and in the module context.

Expected behavior
Since the config file /usr/lib/node_modules/@doyensec/electronegativity/.eslintrc.json specifies the necessary options for parsing as a module:

    "parserOptions": {
        "ecmaVersion": 2017,
        "sourceType": "module"
    },

Therefore I would expect app.js to be parsed without problems.

Platform (please complete the following information):

  • OS: Ubuntu 18.04
  • Electronegativity version: 1.3.2
@ikkisoft
Copy link
Contributor

Thanks for the report. Is there any way that you could provide the code (or sanitized code) that trigger the error?

@vollkorn1982
Copy link
Author

I reduced the code to a sample I can post here. The project folder is a single file app.js, which contains only the following line:

import { app, BrowserWindow, Menu, MenuItem, ipcMain, shell, dialog, remote } from 'electron';

This produces exactly the same error as above.

@ikkisoft
Copy link
Contributor

That's great. We will take a look during the next week or so.

@ikkisoft ikkisoft added the bug label Sep 11, 2019
@vollkorn1982
Copy link
Author

Hi, it's been a month and I want to introduce this tool to my colleagues early in November. Is there any way I can help with that?

I figured out that this is a problem with eslint and there seem to be several ways to fix this: eslint/eslint#4344

  • update eslint and babel-eslint as dependency for electronegativity
  • add some config parameters in .eslintrc (but I don't know where to place this file for it to be used)

@ikkisoft
Copy link
Contributor

Apologies for the delay, but unfortunately we still didn't find time to fix this issue. Rest assured - it's on our roadmap!

@ikkisoft
Copy link
Contributor

Took a quick look in the past 5 minutes, but it's not just a simple dep upgrade. Updating eslint causes a new error Error: Cannot find module 'eslint/lib/util/traverser' due to a eslint's plugin (which I believe was removed in newer version).

@phosphore
Copy link
Contributor

phosphore commented Oct 14, 2019

Hello @vollkorn1982 and thank you for your report,

Upgrading eslint was not enough to fix the issue, but we found that we did not extend the sourceType: "module" configuration of our AST parser to our scoping library (escope).

Let me know if you are still experiencing the problem after this fix.

@vollkorn1982
Copy link
Author

Hi, I would really love to test these changes, but fail to install the current version from the repo.

$ npm install https://github.com/doyensec/electronegativity.git
npm WARN enoent ENOENT: no such file or directory, open '/home/work/Dokumente/electronegativity/package.json'
npm WARN electronegativity No description
npm WARN electronegativity No repository field.
npm WARN electronegativity No README data
npm WARN electronegativity No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/@doyensec/electronegativity/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /home/work/Dokumente/electronegativity/node_modules/@doyensec/electronegativity/dist/index.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/work/Dokumente/electronegativity/node_modules/@doyensec/electronegativity/dist/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/work/.npm/_logs/2019-10-17T15_10_01_031Z-debug.log

And indeed, that path does not exist because the install is from git:

find . -name "index.js"
./electronegativity-master/src/util/index.js
./electronegativity-master/src/loader/index.js
./electronegativity-master/src/parser/index.js
./electronegativity-master/src/finder/checks/GlobalChecks/index.js
./electronegativity-master/src/finder/checks/AtomicChecks/index.js
./electronegativity-master/src/finder/index.js
./electronegativity-master/src/index.js

How do you do it?

@phosphore
Copy link
Contributor

You will need to use git clone and then npm install . && npm run build for now.
We'll soon release a new version on npm with the fix for this issue.

@vollkorn1982
Copy link
Author

Thanks a lot for the help. I managed to install and test the current master branch now and can confirm that this fixes the problem I described in this bug. Great tool!

@phosphore
Copy link
Contributor

Glad to help. Let us know what your colleagues think of the tool! Electronegativity is always accepting new contributors or ideas :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants