Found syntax error when bundling fast-glob:
Repro:
git clone https://gist.github.com/7f5cb8d054337c0b1a8217501305514f.git ncc-bug
cd ncc-bug
npm i
npx ncc build input.js
logs:
ncc: Version 0.20.1
ncc: Compiling file index.js
Error: Module build failed (from (webpack)/ncc/loaders/relocate-loader.js):
SyntaxError: Unexpected token (22:10)
at Object.re.raise (evalmachine.<anonymous>:1:271099)
at Object.V.unexpected (evalmachine.<anonymous>:1:227376)
at Object.ee.parseIdent (evalmachine.<anonymous>:1:270282)
at Object.parseIdent (evalmachine.<anonymous>:1:466467)
at Object.parseIdent (evalmachine.<anonymous>:1:191232)
at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:266678)
at Object.parsePropertyName (evalmachine.<anonymous>:1:4077)
at Object.Q.parseClassElement (evalmachine.<anonymous>:1:241588)
at Object.parseClassElement (evalmachine.<anonymous>:1:464657)
at Object.parseClassElement (evalmachine.<anonymous>:1:187765)
Module build failed (from (webpack)/ncc/loaders/relocate-loader.js):
SyntaxError: Unexpected token (23:10)
at Object.re.raise (evalmachine.<anonymous>:1:271099)
at Object.V.unexpected (evalmachine.<anonymous>:1:227376)
at Object.ee.parseIdent (evalmachine.<anonymous>:1:270282)
at Object.parseIdent (evalmachine.<anonymous>:1:466467)
at Object.parseIdent (evalmachine.<anonymous>:1:191232)
at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:266678)
at Object.parsePropertyName (evalmachine.<anonymous>:1:4077)
at Object.Q.parseClassElement (evalmachine.<anonymous>:1:241588)
at Object.parseClassElement (evalmachine.<anonymous>:1:464657)
at Object.parseClassElement (evalmachine.<anonymous>:1:187765)
at compiler.close.n (evalmachine.<anonymous>:1:1539315)
at _promise0.then._result0 (eval at create (evalmachine.<anonymous>:1:273321), <anonymous>:13:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Thanks! I was able to reproduce this issue.
I recently struggled with this same error trying to build fast-glob with browserify. Using the @babel/preset-env transform solved the problem, though I'm not sure which syntax transform solved it, or how you would do the same in webpack.
Fixed in 0.20.4 via https://github.com/zeit/ncc/pull/448.
@guybedford @styfle I still face the same issue with version 0.20.4 but not sure which dependency is causing it
2019-07-16T10:24:54.555Z Error: Module build failed (from /tmp/6f7bd075/.build-utils/.builder/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js):
SyntaxError: Unexpected token (16:10)
at Object.re.raise (evalmachine.<anonymous>:1:266416)
at Object.z.unexpected (evalmachine.<anonymous>:1:222693)
at Object.ee.parseIdent (evalmachine.<anonymous>:1:265599)
at Object.parseIdent (evalmachine.<anonymous>:1:461728)
at Object.parseIdent (evalmachine.<anonymous>:1:186548)
at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:261995)
at Object.parsePropertyName (evalmachine.<anonymous>:1:4333)
at Object.H.parseClassElement (evalmachine.<anonymous>:1:236905)
at Object.parseClassElement (evalmachine.<anonymous>:1:459918)
at Object.parseClassElement (evalmachine.<anonymous>:1:183081)
Module build failed (from /tmp/6f7bd075/.build-utils/.builder/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js):
SyntaxError: Unexpected token (15:10)
at Object.re.raise (evalmachine.<anonymous>:1:266416)
at Object.z.unexpected (evalmachine.<anonymous>:1:222693)
at Object.ee.parseIdent (evalmachine.<anonymous>:1:265599)
at Object.parseIdent (evalmachine.<anonymous>:1:461728)
at Object.parseIdent (evalmachine.<anonymous>:1:186548)
at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:261995)
at Object.parsePropertyName (evalmachine.<anonymous>:1:4333)
at Object.H.parseClassElement (evalmachine.<anonymous>:1:236905)
at Object.parseClassElement (evalmachine.<anonymous>:1:459918)
at Object.parseClassElement (evalmachine.<anonymous>:1:183081)
at compiler.close.n (evalmachine.<anonymous>:3:1350338)
at _promise0.then._result0 (eval at create (evalmachine.<anonymous>:1:349386), <anonymous>:13:1)
at <anonymous>
how can i debug this?
My issue was that the deployment environment was still using the old version of ncc but not sure how to upgrade it to 0.20.4
If you're using ZEIT Now, you can try the latest builder @now/node@canary.
@styfle it's building correctly after i tried canary but i am facing the following issue when trying to access the deployment URL
2019-07-16T16:07:02.708Z 8f2fbb84-5482-48bc-bd92-aeae76e8e330 Cannot find module '@nodelib/fs.stat'
2019-07-16T16:07:02.708Z 8f2fbb84-5482-48bc-bd92-aeae76e8e330 Did you forget to add it to "dependencies" in `package.json`?
@gimyboya Are you using yarn workspaces? There is a known bug we are working on with symlinks.
Oh right, I am.
Should I switch to npm?
You can try referencing the path directly (probably require('fs') in your case) instead of the workspace symlink.
Follow this PR which will probably be fixed today or tomorrow https://github.com/zeit/now-builders/pull/765
Most helpful comment
If you're using ZEIT Now, you can try the latest builder
@now/node@canary.