storybook: Error when running build-storybook with Node 17

Describe the bug When I running the cmd line ̀yarn build-storybook -c .storybook -o build/storybook` with Node 17. I received this error:

10% building 1/11 modules 10 active /home/belliard/dev/my-app/node_modules/@storybook/addon-links/dist/esm/preset/addDecorator.js-generated-other-entry.jsnode:internal/crypto/hash:67
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (/home/belliard/dev/my-app/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/home/belliard/dev/my-app/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/home/belliard/dev/my-app/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/NormalModule.js:471:10)
    at /home/belliard/dev/my-app/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/NormalModule.js:503:5
    at /home/belliard/dev/my-app/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/NormalModule.js:358:12
    at /home/belliard/dev/my-app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/home/belliard/dev/my-app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at /home/belliard/dev/my-app/node_modules/loader-runner/lib/LoaderRunner.js:205:4
    at /home/belliard/dev/my-app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:85:15
    at processTicksAndRejections (node:internal/process/task_queues:78:11) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.0.1

I create a CRA project in order to reproduce the bug, and I get the error. An issue on webpack was opened (#14532) and a workaround was found using

export NODE_OPTIONS=--openssl-legacy-provider

To Reproduce

  • Create a react project with CRA
  • Run npx sb init
  • Run yarn build-storybook -c .storybook -o build/storybook

System

Environment Info:

  System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 PRO 4650U with Radeon Graphics
  Binaries:
    Node: 17.0.1 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 95.0.4638.69
    Firefox: 93.0
  npmPackages:
    @storybook/addon-actions: ^6.3.12 => 6.3.12 
    @storybook/addon-essentials: ^6.3.12 => 6.3.12 
    @storybook/addon-links: ^6.3.12 => 6.3.12 
    @storybook/node-logger: ^6.3.12 => 6.3.12 
    @storybook/preset-create-react-app: ^3.2.0 => 3.2.0 
    @storybook/react: ^6.3.12 => 6.3.12 

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 61
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This issue seems to remains for with builder-vite, as I understand manager-webpack4 is still used.

More users may run into this issue as node.js 16’s EOL is 7 months ahead of schedule.

When we put together Node.js 16 the hope was that we would be able to include OpenSSL 3. Unfortunately, the timing of the releases did not allow that to be possible, and we released Node.js 16 with OpenSSL 1.1.1. OpenSSL 1.1.1 is scheduled to be supported up until September 11th, 2023, which is seven months before the planned End-of-Life date of Node.js 16 (April 2024). https://nodejs.org/en/blog/announcements/nodejs16-eol/

I’m temporarily avoiding it by enabling the node environment variable in direnv.

export NODE_OPTIONS=--openssl-legacy-provider

If webpack 4 isn’t patched, perhaps the other solutions listed in this article would resolve the issue for some users:

https://onlinessolution.blogspot.com/2021/11/error-error0308010cdigital-envelope.html

This fixed my problem: https://www.npmjs.com/package/@storybook/manager-webpack5

Removed @storybook/builder-webpack4 and @storybook/manager-webpack4 , node_modules and lock files. Then install v5. And follow the instuctions on above link.

@hlehmann that’s true in 6.5, but in 7.0 webpack is not used in the vite builder at all. I’d suggest trying out the new alpha version if you’re having issues here. npx sb@next upgrade --prerelease.

(Edited command)

@hlehmann that’s true in 6.5, but in 7.0 webpack is not used in the vite builder at all. I’d suggest trying out the new alpha version if you’re having issues here. npx sb@future upgrade --prerelease.

future did not work for me This one did: npx sb@next upgrade --prerelease

Hi, I’m using webpack 5.65.0, node 17.4.0, and storybook 6.5.0-alpha.49. I’m encountering this issue. I was able to solve it locally by putting NODE_OPTIONS=--openssl-legacy-provider at the start of my storybook build/start commands, but this doesn’t work on our CI - the node option is blocked because of security concerns. We will downgrade node to 16 for now, but I want to ask: What are the plans here? Will this be solved by the Storybook team in the future?

I got same error with svelte kit project

Getting back 20 minutes later - I actually found a culprit. You were right this is fixed in the new webpack version, the problem was that the @storybook/builder-webpack5 package defines its own webpack: ^5.9.0 dependency, which in yarn.lock had an old resolution. So I:

  • removed the whole "webpack@npm:^5.9.0": part of yarn.lock
  • ran yarn to re-resolve dependencies

After this, it works.

However, this means the Storybook team should update the webpack dependency of @storybook/builder-webpack5 so other people don’t run into this problem anymore.

Thanks, I ran yarn dedupe instead of manually editing the lock file and this resolved my issue

Getting back 20 minutes later - I actually found a culprit. You were right this is fixed in the new webpack version, the problem was that the @storybook/builder-webpack5 package defines its own webpack: ^5.9.0 dependency, which in yarn.lock had an old resolution. So I:

  • removed the whole "webpack@npm:^5.9.0": part of yarn.lock
  • ran yarn to re-resolve dependencies

After this, it works.

However, this means the Storybook team should update the webpack dependency of @storybook/builder-webpack5 so other people don’t run into this problem anymore.

Adding this configuration to .storybook/main.ts solved the issue for me;

module.exports = {
  // ...
  webpackFinal: async config => {
    config.output.hashFunction = 'xxhash64'

    // Return the altered config
    return config
  }
}

Migrating to webpack 5 did the job for me.

Please note that this command is for fresh installation: npx sb init --builder webpack5 By default storybook installed webpack4 and it was causing the issue