minified dist/server/index.js throws error with `next build`
ddombrowsky opened this issue ยท 9 comments
Context
Please forgive my frustration, as I'm unsure where the root cause of this error even is.
After upgrading spree SDK to latest (4.7.2), I am unable to build my site.
To make a test build, I normally run npx next build
, and that pre-compiles everything.
info - Using external babel configuration from /home/davek/work/instinct/dna/dna-frontend/.babelrc
info - Creating an optimized production build
Failed to compile.
./node_modules/@spree/storefront-api-v2-sdk/dist/server/index.js 1:521
Module parse failed: Unexpected token (1:521)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
>
... minified js file removed ...
> Build error occurred
Error: > Build failed because of webpack errors
at /home/davek/work/instinct/dna/dna-frontend/node_modules/next/dist/build/index.js:15:918
at async /home/davek/work/instinct/dna/dna-frontend/node_modules/next/dist/build/tracer.js:1:1441
Does anyone have any idea what the root cause is? I'm not even sure if it is babel or webpack or what is trying to parse this minified file, nor can I divine a configuration that will set it to be ignored from building (assuming that would even work, which it probably would not).
versions:
- webpack 4.46.0
- next 10.0.6
- storefront-api-v2-sdk 4.7.2
Note that pinning the build to use version 4.6.0
of storefront-api-v2-sdk
does work. I'll have to do that in the meantime.
Hi @ddombrowsky,
Thanks for creating the issue.
./node_modules/@spree/storefront-api-v2-sdk/dist/server/index.js 1:521
contains optional chaining (i.e. ?.
, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) added in Spree SDK 4.7.0. We use the SDK with NextJS 11 and it works fine with that version. So, support for optional chaining was added between versions 10.0.6
and 11
of NextJS. Digging deeper, based on comments in Webpack's GitHub repo, Webpack 5 supports optional chaining and 4 doesn't (webpack/webpack#10227). It's possible Babel is letting optional chaining through.
We added optional chaining in just one place in the source code. We'll replace it with older syntax and release a new version of the SDK.
@ddombrowsky https://github.com/spree/spree-storefront-api-v2-js-sdk/releases/tag/v4.8.0. Let me know how the new version works for you.
@tniezg
Wonderful! Version 4.8.0
does indeed fix the build issue. tyvm
This appears to be once again broken on v4.9.0.
@aforty That's true! The new src/helpers/jsonApi.ts
helper is the culprit. We'll fix that in 4.10.0
. Thank you for reporting the issue.
T.
We'll release 4.10.0
containing this and other recent changes today. Will be an easy upgrade from 4.9.0
.