GithubHelp home page GithubHelp logo

errored out during transformation TypeError: /PROJECT/pages/404.js: Cannot read property 'constant' of undefined about optimize-plugin HOT 10 OPEN

developit avatar developit commented on July 28, 2024 2
errored out during transformation TypeError: /PROJECT/pages/404.js: Cannot read property 'constant' of undefined

from optimize-plugin.

Comments (10)

developit avatar developit commented on July 28, 2024

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,
    }
};

from optimize-plugin.

mohsinulhaq avatar mohsinulhaq commented on July 28, 2024

@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)

from optimize-plugin.

developit avatar developit commented on July 28, 2024

@mohsinulhaq what version of Webpack are you using?

from optimize-plugin.

mohsinulhaq avatar mohsinulhaq commented on July 28, 2024

@developit [email protected]

from optimize-plugin.

rockeynebhwani avatar rockeynebhwani commented on July 28, 2024

@developit - Is this supposed to work on Webpack versions < 5 ?

from optimize-plugin.

developit avatar developit commented on July 28, 2024

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.

from optimize-plugin.

Super-Fly avatar Super-Fly commented on July 28, 2024

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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild:production', 'build:production', 'postbuild:production' ]
5 info lifecycle [email protected]~prebuild:production: [email protected]
6 info lifecycle [email protected]~build:production: [email protected]
7 verbose lifecycle [email protected]~build:production: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~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 [email protected]~build:production: CWD: C:\Users\WIN_USERNAME\Workspaces\_project-folder\cartridge\react
10 silly lifecycle [email protected]~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 [email protected]~build:production: Returned: code: 2  signal: null
12 info lifecycle [email protected]~build:production: Failed to exec build:production script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] 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 [email protected] 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 ]

from optimize-plugin.

developit avatar developit commented on July 28, 2024

@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?

from optimize-plugin.

Super-Fly avatar Super-Fly commented on July 28, 2024

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
      })

from optimize-plugin.

developit avatar developit commented on July 28, 2024

@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.

from optimize-plugin.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.