Open meesrutten opened 3 years ago
Hiya - try passing modernize:false
:
webpack: config => {
config.plugins.push(new OptimizePlugin({ modernize: false }));
return config;
},
That should perhaps be the default, since it's very much a thing that can break.
FWIW Next.js has its own way of generating modern + legacy output, and I'm not sure this plugin will do a better job of it. I believe you can enable it by doing:
module.exports = {
experimental: {
modern: true,
}
};
@developit I faced a similar issue in a normal webpack app. The errors I was getting were this plus many others like:
Cannot read property 'arguments' of undefined
Cannot read property 'referencePaths' of undefined
Cannot read property 'node' of undefined
Then I used modernize: false
as suggested above, and now the error is:
errored out during transformation Error: xxx/app.prod.a60be814.js: Not a webpack bundle
at mod (xxx/node_modules/optimize-plugin/dist/worker.js:203:15)
@mohsinulhaq what version of Webpack are you using?
@developit webpack@4.43.0
@developit - Is this supposed to work on Webpack versions < 5 ?
Yes - I haven't tested it on Webpack 5+.
I'm thinking the issue here is related to Webpack output options folks have configured - output.target
, etc. If anyone can post their output config that would be useful.
Hey, Had the same error plus those below
vendors..bundle.js: v.forEach is not a function
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
8..bundle.js: Cannot read property 'arguments' of undefined
after applying modernize:false
the errors are gone but the build is failing like that
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build:production'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v12.20.0
4 verbose run-script [ 'prebuild:production', 'build:production', 'postbuild:production' ]
5 info lifecycle React@0.0.1~prebuild:production: React@0.0.1
6 info lifecycle React@0.0.1~build:production: React@0.0.1
7 verbose lifecycle React@0.0.1~build:production: unsafe-perm in lifecycle true
8 verbose lifecycle React@0.0.1~build:production: PATH: C:\Users\WIN_USERNAME\AppData\Roaming\nvm\v12.20.0\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\WIN_USERNAME\Workspaces\_project-folder\cartridge\react\node_modules\.bin;C:\Users\WIN_USERNAME\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\WIN_USERNAME\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ActiveTcl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\WIN_USERNAME\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\Java\jdk-11\bin;C:\PROGRA~2\Groovy\Groovy-2.5.7\bin;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\PuTTY;C:\Python27\Scripts;C:\Python27;C:\Python3;C:\Python3\Scripts;C:\Users\WIN_USERNAME\AppData\Local\Microsoft\WindowsApps;C:\Users\WIN_USERNAME\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\JetBrains\PyCharm Community Edition 2018.3\bin;C:\Users\WIN_USERNAME\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle React@0.0.1~build:production: CWD: C:\Users\WIN_USERNAME\Workspaces\_project-folder\cartridge\react
10 silly lifecycle React@0.0.1~build:production: Args: [
10 silly lifecycle '/d /s /c',
10 silly lifecycle 'cross-env NODE_ENV=production webpack --env production --progress -p --json > stats.json'
10 silly lifecycle ]
11 silly lifecycle React@0.0.1~build:production: Returned: code: 2 signal: null
12 info lifecycle React@0.0.1~build:production: Failed to exec build:production script
13 verbose stack Error: React@0.0.1 build:production: `cross-env NODE_ENV=production webpack --env production --progress -p --json > stats.json`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (C:\Users\WIN_USERNAME\AppData\Roaming\nvm\v12.20.0\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:314:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\WIN_USERNAME\AppData\Roaming\nvm\v12.20.0\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:314:20)
13 verbose stack at maybeClose (internal/child_process.js:1022:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid React@0.0.1
15 verbose cwd C:\Users\WIN_USERNAME\Workspaces\_project-folder\cartridge\react
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build:production"
18 verbose node v12.20.0
19 verbose npm v6.14.8
20 error code ELIFECYCLE
21 error errno 2
22 error React@0.0.1 build:production: `cross-env NODE_ENV=production webpack --env production --progress -p --json > stats.json`
22 error Exit status 2
23 error Failed at the React@0.0.1 build:production script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
@Super-Fly unfortunately that error message only tells me that webpack failed to complete successfully (the stack trace is just from npm run
). Are you able to share the repository or webpack configuration you're using?
ah @developit I had to remove the changes that I made to test the plugin and now when I applied them again, it worked ... sorry for bothering you.
btw the difference that we received in bundles are those: Non legacy bundles - 3.7 mb total Legacy bundles - 3.8 mb total
Bundles without the plugin - 3.8 mb total
this is the plugin config
new OptimizePlugin({
'sourceMap': false,
'minify': true,
'downlevel': true,
'verbose': false,
'modernize': false
})
@Super-Fly hmm - those numbers mean something is misconfigured. Are you running babel-loader or transpiling typescript? Need to remove babel-loader to use this.
Hi there 👋
I ran into this issue when adding optimize-plugin to my nextjs project.
babel.rc
package.json
next.config.js
Any idea?