next.js: swcMinify: true leads to "Expected ident" Webpack/Terser error
What version of Next.js are you using?
11.1.3-canary.81
What version of Node.js are you using?
14.16.1
What browser are you using?
Firefox
What operating system are you using?
macOS
How are you deploying your application?
next dev/next build/Vercel
Describe the Bug
I opted into the SWC compiler and am getting this error when I try to run yarn build:
Now, I’m getting an issue with Terser, that seems to go away when I remove swcMinify: true from my next.config.js
info - Creating an optimized production build
Failed to compile.
static/chunks/2095-3910ce9329e0dc7f.js from Terser
error: Expected ident
|
116692 | var await = is("name", "await") && next();
| ^^^^^
Caused by:
0: failed to parse input file
1: Syntax Error
Error: error: Expected ident
|
116692 | var await = is("name", "await") && next();
| ^^^^^
Caused by:
0: failed to parse input file
1: Syntax Error
> Build failed because of webpack errors
Previous issue
info - Checking validity of types
info - Creating an optimized production build
Failed to compile.
./src/components/form/percent-input.tsx
Module parse failed: Identifier '_templateObject' has already been declared (92:9)
File was processed with these loaders:
* ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
You may need an additional loader to handle the result of these loaders.
| return data;
| }
> function _templateObject() {
| var data = _taggedTemplateLiteral([
| "\n input {\n text-align: right;\n }\n "
> Build error occurred
Error: > Build failed because of webpack errors
at /Users/omar/code/spinach/web-app/node_modules/next/dist/build/index.js:400:19
at async Span.traceAsyncFn (/Users/omar/code/spinach/web-app/node_modules/next/dist/trace/trace.js:74:20)
at async Object.build [as default] (/Users/omar/code/spinach/web-app/node_modules/next/dist/build/index.js:78:25)
Expected Behavior
No errors on yarn build
To Reproduce
I’m not sure what it is about this project that causes the issue - it’s a nextJS project that uses Emotion with the CSS prop - I tried making a similar repro project but it doesn’t fail like this, so I’m happy to grant access to my company’s codebase to see if there’s somethign I’m doing wrong, but here’s some data:
Language: Typescript 4.4.3
next.config.js
const { merge: webpackMerge } = require("webpack-merge");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { withSentryConfig } = require("@sentry/nextjs");
const config = {
experimental: {
swcLoader: true,
swcMinify: true,
},
// ...
webpack5: true,
webpack: (config, options) =>
webpackMerge(config, {
...(options.isServer ? {} : { resolve: { fallback: { fs: false } } }),
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
type: "asset/resource",
generator: {
filename: "static/chunks/[path][name].[hash][ext]",
},
},
{
test: /\.svg$/,
use: [
{
loader: "@svgr/webpack",
options: {
svgoConfig: {
plugins: {
// `removeDimensions` also sets a `viewBox` which we want
removeDimensions: true,
},
},
},
},
],
},
],
},
plugins: [
...(process.env.ANALYZE
? [
new BundleAnalyzerPlugin({
analyzerMode: "server",
analyzerPort: options.isServer ? 8888 : 8889,
openAnalyzer: true,
}),
]
: []),
],
}),
};
// Make sure adding Sentry options is the last code to run before exporting, to
// ensure that your source maps include changes from all other Webpack plugins
const sentryConfig = withSentryConfig(config, {
// ...
});
// as per https://github.com/getsentry/sentry-javascript/issues/3549
const stashedWebpackConfig = sentryConfig.webpack;
sentryConfig.webpack = (config, options) => {
const updatedConfig = stashedWebpackConfig(config, options);
// see: https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md
if (!options.dev) {
updatedConfig.devtool = "hidden-source-map";
}
return updatedConfig;
};
module.exports = sentryConfig;
Relevant Deps
"dependencies": {
"@emotion/react": "^11.5.0",
"@sentry/integrations": "^6.13.3",
"@sentry/nextjs": "^6.12.0",
"next": "canary",
// ...
},
"devDependencies": {
"@emotion/eslint-plugin": "^11.5.0",
"@emotion/serialize": "^1.0.2",
"@svgr/webpack": "^5.5.0",
// ...
"typescript": "^4.4.3",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-merge": "^5.7.3"
},
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (7 by maintainers)
This is released as https://github.com/vercel/next.js/releases/tag/v12.0.4-canary.13 which can be installed using
npm install next@canary. It’s currently being published to npm which takes around 30 minutes, after that you can install and run the following command:This should be fixed, as the swc minifier has module mode (false by default) and ES codegen bugs are resolved.