ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Error parsing code with Ember 3.0.0 #128

Closed artcommacode closed 6 years ago

artcommacode commented 6 years ago

Error parsing code while looking for "npm:" imports: SyntaxError: Unexpected token (5:40)

Error log:

ERROR Summary:

  - broccoliBuilderErrorStack: Error: Error parsing code while looking for "npm:" imports: SyntaxError: Unexpected token (5:40)
    at Parser.pp$4.raise (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2610:13)
    at Parser.pp.unexpected (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:637:8)
    at Parser.pp$1.parseVar (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1130:14)
    at Parser.pp$1.parseVarStatement (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:999:8)
    at Parser.pp$1.parseStatement (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:771:17)
    at Parser.pp$1.parseBlock (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1076:23)
    at Parser.pp$3.parseFunctionBody (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2466:22)
    at Parser.pp$1.parseFunction (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1177:8)
    at Parser.pp$3.parseExprAtom (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2082:17)
    at Parser.pp$3.parseExprSubscripts (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1955:19)
    at Parser.pp$3.parseMaybeUnary (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1932:17)
    at Parser.pp$3.parseExprOps (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1874:19)
    at Parser.pp$3.parseMaybeConditional (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1857:19)
    at Parser.pp$3.parseMaybeAssign (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1832:19)
    at Parser.pp$3.parseExprList (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2528:20)
    at Parser.pp$3.parseSubscripts (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1983:29)
    at importsFor (/***/node_modules/ember-browserify/lib/stubs.js:67:11)
    at Stub.set (/***/node_modules/ember-browserify/lib/stubs.js:31:25)
    at StubGenerator.<anonymous> (/***/node_modules/ember-browserify/lib/stub-generator.js:57:33)
    at Array.forEach (<anonymous>)
    at StubGenerator.build (/***/node_modules/ember-browserify/lib/stub-generator.js:49:12)
    at /***/node_modules/broccoli-plugin/read_compat.js:93:34
    at tryCatch (/***/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/***/node_modules/rsvp/dist/rsvp.js:538:13)
    at publish (/***/node_modules/rsvp/dist/rsvp.js:508:7)
    at flush (/***/node_modules/rsvp/dist/rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  - codeFrame: Error parsing code while looking for "npm:" imports: SyntaxError: Unexpected token (5:40)
    at Parser.pp$4.raise (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2610:13)
    at Parser.pp.unexpected (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:637:8)
    at Parser.pp$1.parseVar (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1130:14)
    at Parser.pp$1.parseVarStatement (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:999:8)
    at Parser.pp$1.parseStatement (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:771:17)
    at Parser.pp$1.parseBlock (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1076:23)
    at Parser.pp$3.parseFunctionBody (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2466:22)
    at Parser.pp$1.parseFunction (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1177:8)
    at Parser.pp$3.parseExprAtom (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2082:17)
    at Parser.pp$3.parseExprSubscripts (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1955:19)
    at Parser.pp$3.parseMaybeUnary (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1932:17)
    at Parser.pp$3.parseExprOps (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1874:19)
    at Parser.pp$3.parseMaybeConditional (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1857:19)
    at Parser.pp$3.parseMaybeAssign (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1832:19)
    at Parser.pp$3.parseExprList (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:2528:20)
    at Parser.pp$3.parseSubscripts (/***/node_modules/ember-browserify/node_modules/acorn/dist/acorn.js:1983:29)
  - errorMessage: The Broccoli Plugin: [object Object] failed with:
  - errorType: Build Error
  - location:
    - file: [undefined]
    - treeDir: [undefined]
  - message: The Broccoli Plugin: [object Object] failed with:
  - name: Error
  - nodeAnnotation: StubGenerator
  - nodeName: StubGenerator

Let me know if there's anything else I can provide for you.

ef4 commented 6 years ago

If you can figure out what file it was trying to parse when it blew up that would be helpful.

One idea would be to put breakpoints in some places mentioned in that stack trace.

halfbyte commented 6 years ago

@ef4 I'm running into this issue as well and in my case it seems to be a weird transformation issue in combination with ember-electron. The parser borks on the following line, which is, as far as I can see, not valid JS:

const { app, BrowserWindow, protocol };

The original file, which is "tests/ember-electron/main.js" looks like this:

const { app, BrowserWindow, protocol } = require('electron');

So something in the build process is mangling the file. I'm not familiar enough with the build process to quickly figure out what's going on there, but I'll take a look at other updates I made together with the ember update to see if I can find something.

One thing that probably needs fixing is the way the error message is constructed as the humongous stack trace of the error completely swallows the important bit that is supposed to be in there, which is the full path to the file in question, see stubs.js.

@artcommacode The easiest way of figuring out the real culprit seems to be to patch the stubs.js file of ember-browserify locally (namely the importsFor function) to just console.log out the fullPath and the actual source of the file (as it operates on processed files) so that you can see where exactly the parser borks.

artcommacode commented 6 years ago

Finally got the time to look into this properly and turns out it's failing for me at exactly the same place is for @halfbyte. (/tests/ember-electron/main.js)

For now I've simply hacked up ember-browserify to stop Throwing errors when it encounters them but I'm also wondering if it needs to be doing this in the first place? Or maybe there's a different way of handling this?

ef4 commented 6 years ago

I went looking for where that file is coming from and it doesn't exist in current versions of ember-electron. I think they deliberately moved it because it was being transpiled incorrectly:

https://github.com/felixrieseberg/ember-electron/pull/284

artcommacode commented 6 years ago

Thanks @ef4, that makes things even easier! I'm happy with this solution