npmwebpackvaadinvaadin-flowvaadin14

Webpack fails due to missing terser module when starting Vaadin 14 application


I'm in the process of incrementally upgrading a Vaadin 7 application to Vaadin 24. Currently I'm upgrading from Vaadin 8 to Vaadin 14. My npm version is 6.14.10. When I start the application, webpack encounters the following error which causes a java.lang.IllegalStateException: Webpack exited prematurely error when accessing the Vaadin UI:

Webpack failed with the exception:
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'terser'
Require stack:
- C:\...\my-app\node_modules\webpack-babel-multi-target-plugin\dist\src\safari-nomodule-fix\safari.nomodule.fix.plugin.js
- C:\...\my-app\node_modules\webpack-babel-multi-target-plugin\dist\src\babel.multi.target.plugin.js
- C:\...\my-app\node_modules\webpack-babel-multi-target-plugin\dist\index.js
- C:\...\my-app\webpack.generated.js
- C:\...\my-app\webpack.config.js
- C:\...\my-app\node_modules\webpack-cli\bin\utils\convert-argv.js
- C:\...\my-app\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\...\my-app\node_modules\webpack-babel-multi-target-plugin\dist\src\safari-nomodule-fix\safari.nomodule.fix.plugin.js:14:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\...\my-app\node_modules\webpack-babel-multi-target-plugin\dist\src\babel.multi.target.plugin.js:9:38)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\...\\my-app\\node_modules\\webpack-babel-multi-target-plugin\\dist\\src\\safari-nomodule-fix\\safari.nomodule.fix.plugin.js',
    'C:\\...\\my-app\\node_modules\\webpack-babel-multi-target-plugin\\dist\\src\\babel.multi.target.plugin.js',
    'C:\\...\\my-app\\node_modules\\webpack-babel-multi-target-plugin\\dist\\index.js',
    'C:\\...\\my-app\\webpack.generated.js',
    'C:\\...\\my-app\\webpack.config.js',
    'C:\\...\\my-app\\node_modules\\webpack-cli\\bin\\utils\\convert-argv.js',
    'C:\\...\\my-app\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
  ]
}

Further up in the application's log, I see that npm logged the following warning message:

npm WARN webpack-babel-multi-target-plugin@2.5.0 requires a peer of terser@>=3.12.0 but none is installed. You must install peer dependencies yourself.

Here are a few things I have tried that have not resolved the issue:

Does anyone have any other ideas about how I can resolve this issue?


Solution

  • I had a similar issue. I am not using node for anything else except for running vaadin, so I uninstalled node completely from my system and let vaadin manage the node stuff. Here is what worked for me:

    1. Uninstall node from my system.
    2. Delete contents of .vaadin directory
    3. Delete the directory node_modules from my project directory
    4. Delete the files package.json, package-lock.json, tsconfig.json and types.d.ts from my project directory
    5. using maven, run mvn install inside the project directory

    If you are using modules, steps 3-5 may have to be repeated for each affected module.