nuxt: Nuxt2 default setup doesn't work with latest node LTS version 18.12.1

The default Nuxt2 project setup runs into an error Error: error:0308010C:digital envelope routines::unsupported when starting the development environment (yarn dev) using node v18.12.1.

Reason For The Error In Node.js v17, the Node.js developers closed a security hole in the SSL provider. This fix was a breaking change that corresponded with similar breaking changes in the SSL packages in NPM. Webpack 4.46.0 (a module currently used by nuxt2 for serving) is using a deprecated hashing algorithm md4 for it’s SSL encryption, which I assume was patched out in Node.js v17.

⚠️ DANGER

Almost all threads found online regarding this issue are suggesting to either downgrade Node.js to pre v17 or to use the legacy SSL provider. Both of those solutions are hacks that leave your builds open to security threats.

This is a big issue because the prerequisites in the current nuxt installation guide are telling newcomers to get the latest node LTS version, which is currently 18.12.1. Googling the error message (which they will definitely get) will lead them to either set NODE_OPTIONS=--openssl-legacy-provider or downgrade Node.js to pre v17.

Versions

  • nuxt: v2.15.8
  • node: v18.12.1

Reproduction

GitHub repository: https://github.com/michael-pfister/nuxt2-node-demonstrations

Additional Details
Make sure you have the currently latest node LTS version (v18.12.1) installed before running any build commands.

Steps to reproduce

# clone git repository
$ git clone https://github.com/michael-pfister/nuxt2-node-demonstrations

# cd into the repository
$ cd nuxt2-node-demonstrations

# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn dev

What is Expected?

The Nuxt2 default setup, which newcomers install using yarn create nuxt-app <project-name> after getting the latest node LTS version as mentioned in the prerequisites should work without throwing an error, that is leading them to implement a potential security risk.

What is actually happening?

node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at Array.<anonymous> (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
    at C:\Users\admin\Desktop\nuxt2-node-demonstrations\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Oh, this issue should be closed. This issue is resolved in v2.16.2.

To be clear, the reason you’re not able to build is that webpack 4, which is used by Nuxt 2, depends on that algorithm for hashing build outputs. But that is a build-time dependency, not a runtime dependency. Nor is it a security risk at build time, as what is being hashed is just the content of the generated files…

More importantly, this is not a vulnerablity in a deployed nuxt site. Once built, a nuxt server can run on node 18 just fine as it has no ongoing dependency on webpack.

That said, if there is an issue on node v18, we do need to update our docs to indicate preferred installation in node 16 for now, which will not release EOL until 2023-09-11, and also consider other options.

Same issue here: Node 18, Nuxt 2.17.2 Webpack 4.47.0

Downgrading to nuxt 2.17.1 fixes the issue

Appears to be re-introduced in 2.17.2.

The same build worked with 2.17.1 but does not with 2.17.2 anymore, Error: error:0308010C:digital envelope routines::unsupported is happening again.

Node 18.16.1

Make sure you refresh your lockfile and are on the latest webpack version, which solves this issue natively.

Thanks for the fast response!
I verified that we (@hokify) have webpack 4.47.0 in use, the latest version.

But I noticed that the error message is coming from compression-webpack-plugin coming from nuxt-compress, which we have added in buildModules - I could imagine its a problem there, and not nuxt itself.

@hokify/website-app:raw:build:app:  FATAL  error:0308010C:digital envelope routines::unsupported
@hokify/website-app:raw:build:app: 
@hokify/website-app:raw:build:app:   at new Hash (node:internal/crypto/hash:71:19)
@hokify/website-app:raw:build:app:   at Object.createHash (node:crypto:133:10)
@hokify/website-app:raw:build:app:   at /home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/compression-webpack-plugin@6.1.1_webpack@4.47.0/node_modules/compression-webpack-plugin/dist/index.js:230:42
@hokify/website-app:raw:build:app:   at CompressionPlugin.compress (/home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/compression-webpack-plugin@6.1.1_webpack@4.47.0/node_modules/compression-webpack-plugin/dist/index.js:319:9)
@hokify/website-app:raw:build:app:   at /home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/compression-webpack-plugin@6.1.1_webpack@4.47.0/node_modules/compression-webpack-plugin/dist/index.js:340:12
@hokify/website-app:raw:build:app:   at _next2 (eval at create (/home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/tapable@1.1.3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:46:17)
@hokify/website-app:raw:build:app:   at eval (eval at create (/home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/tapable@1.1.3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:65:1)
@hokify/website-app:raw:build:app:   at /home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/@nuxt+webpack@2.17.2_prettier@2.8.8_typescript@5.1.6_vue@2.7.15_webpack-cli@4.10.0/node_modules/@nuxt/webpack/dist/webpack.js:284:7
@hokify/website-app:raw:build:app:   at _next1 (eval at create (/home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/tapable@1.1.3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:61:1)
@hokify/website-app:raw:build:app:   at eval (eval at create (/home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/tapable@1.1.3/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:77:1)
@hokify/website-app:raw:build:app:   at /home/pkerschbaum/workspace/hokify/hokify/node_modules/.pnpm/html-webpack-plugin@4.5.2_webpack@4.47.0/node_modules/html-webpack-plugin/index.js:303:11
@hokify/website-app:raw:build:app:   at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@hokify/website-app:raw:build:app: 
@hokify/website-app:raw:build:app: 
@hokify/website-app:raw:build:app:    ╭──────────────────────────────────────────────────────────────────╮
@hokify/website-app:raw:build:app:    │                                                                  │
@hokify/website-app:raw:build:app:    │   ✖ Nuxt Fatal Error                                             │
@hokify/website-app:raw:build:app:    │                                                                  │
@hokify/website-app:raw:build:app:    │   Error: error:0308010C:digital envelope routines::unsupported   │
@hokify/website-app:raw:build:app:    │                                                                  │
@hokify/website-app:raw:build:app:    ╰──────────────────────────────────────────────────────────────────╯

The current workaround is to use Node 16 to build your Nuxt 2 project; you can run the resulting dist files on newer node versions if necessary.

The current workaround is to use Node 16 to build your Nuxt 2 project; you can run the resulting dist files on newer node versions if necessary.

In practice, this will become an obstacle for Nuxt 2 projects that are deployed with many of the popular Jamstack hosting providers, because at some point those hosting providers will drop support build images that use Node.js 16. I don’t think it’s Nuxt’s problem to solve, but it’s a problem that Nuxt practitioners should keep in mind when planning project upgrades from Nuxt 2 to Nuxt 3.

To be clear, the reason you’re not able to build is that webpack 4, which is used by Nuxt 2, depends on that algorithm for hashing build outputs. But that is a build-time dependency, not a runtime dependency. Nor is it a security risk at build time, as what is being hashed is just the content of the generated files…

More importantly, this is not a vulnerablity in a deployed nuxt site. Once built, a nuxt server can run on node 18 just fine as it has no ongoing dependency on webpack.

That said, if there is an issue on node v18, we do need to update our docs to indicate preferred installation in node 16 for now, which will not release EOL until 2023-09-11, and also consider other options.

Thanks so much for clarifying the actual security risk!