jaredpalmer/razzle

Unexpected token: punc (.)

ksolanki9 opened this issue ยท 6 comments

๐Ÿ› Bug report

Current Behavior

Terser is creating issue while minification when minimizing one third part module on local machine.

Unexpected token: punc (.) [webpack://javascript/esm|./node_modules/somethirdpartypackage/dist/components/folder1/file1.js:24,0]
at ne (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:195)
at c (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:282)
at l (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:283)
at f (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:284)
at U (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:422)
at me (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:483)
at c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:492
at ve (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:492)
at ke (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:504)
at We (c:\temp\node_modules\terser-webpack-plugin\node_modules\terser\dist\bundle.min.js:1:507)

If we put minimization off as mentioned here #1012 then it works but then for whole project js compression and minimization not happening. do you know any workaround or exclude some particular node_modules from minification then would be good.

Your environment

Software Version(s)
Razzle 4.2.18
Razzle Plugins 4.2.18
Node 18
Browser NA
npm/Yarn yarn
Operating System windows
TypeScript >5.0
React 18.2

Does your issue solve with React 18.2.0 ? @ksolanki9

I'm also running into a similar issue. Optional chaining works fine in my code but razzle isn't compiling node modules correctly. Any time I install a node module with optional chaining the terser build breaks with Unexpected token: punc (.) . This is preventing me from installing many packages. Is there a way to just update razzle/terser's compilation target?

Update on this, setting webpackConfig.optimization.minimize = false fixes this but also triples the bundle size. Is this really the workaround?

below config fixed my issue, try once
webpackConfig.optimization = {
minimize: true,
splitChunks: {
chunks: 'all'
}
}

Thank you, this works! It works because we removed the plugins from the webpack optimization minimizer though. Did you have any issues with bundle size or unminimized css?

So an update on this, this caused an error in production: Unexpected token '<'.