jaredpalmer / razzle

✨ Create server-rendered universal JavaScript applications with no configuration
https://razzlejs.org
MIT License
11.1k stars 868 forks source link

Unexpected token: punc (.) #1921

Open ksolanki9 opened 11 months ago

ksolanki9 commented 11 months ago

🐛 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 https://github.com/jaredpalmer/razzle/issues/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
bassamIHabash commented 11 months ago

Does your issue solve with React 18.2.0 ? @ksolanki9

ColinFendrick commented 4 months ago

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?

ColinFendrick commented 4 months ago

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

ksolanki9 commented 4 months ago

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

ColinFendrick commented 4 months ago

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?

ColinFendrick commented 4 months ago

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