storybook: Not working with pnpm
Describe the bug Installation with pnpm doesn’t work.
To Reproduce Steps to reproduce the behavior:
In a new folder…
pnpx create-react-app appcd apppnpx sb-initrm -rf node_modulespnpm ipnpm run storybook
Expected behavior Starts normally.
Screenshots
> app@0.1.0 storybook /home/node/x/app
> start-storybook -p 6006 -s public
info @storybook/react v6.1.10
info
info => Loading static files from /home/node/x/app/public and serving at /.
info => Using prebuilt manager
info => Loading presets
info => Loading 1 config file in "./.storybook"
info => Loading 7 other files in "./.storybook"
info => Adding stories defined in ".storybook/main.js"
info => Loading Webpack configuration from `node_modules`
info => Removing existing JavaScript and TypeScript rules.
ERR! Error: Cannot find module '/home/node/x/app/node_modules/config/webpack.config'
ERR! Require stack:
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/preset-create-react-app@3.1.5_9aa452dba90d1f953a1868926ff23f98/node_modules/@storybook/preset-create-react-app/dist/index.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/presets.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/config.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-static.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/server.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/dist/server/index.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/bin/index.js
ERR! at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
ERR! at Function.Module._load (internal/modules/cjs/loader.js:725:27)
ERR! at Module.require (internal/modules/cjs/loader.js:952:19)
ERR! at require (internal/modules/cjs/helpers.js:88:18)
ERR! at Object.exports.webpack (/home/node/x/app/node_modules/.pnpm/@storybook/preset-create-react-app@3.1.5_9aa452dba90d1f953a1868926ff23f98/node_modules/@storybook/preset-create-react-app/dist/index.js:111:28)
ERR! at /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/presets.js:259:28
ERR! at async startPreview (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/dev-server.js:407:23)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/dev-server.js:494:29)
ERR! at async buildDevStandalone (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-dev.js:317:33)
ERR! at async buildDev (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-dev.js:380:3)
ERR! Error: Cannot find module '/home/node/x/app/node_modules/config/webpack.config'
ERR! Require stack:
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/preset-create-react-app@3.1.5_9aa452dba90d1f953a1868926ff23f98/node_modules/@storybook/preset-create-react-app/dist/index.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/presets.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/config.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-static.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/server.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/dist/server/index.js
ERR! - /home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/bin/index.js
ERR! at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
ERR! at Function.Module._load (internal/modules/cjs/loader.js:725:27)
ERR! at Module.require (internal/modules/cjs/loader.js:952:19)
ERR! at require (internal/modules/cjs/helpers.js:88:18)
ERR! at Object.exports.webpack (/home/node/x/app/node_modules/.pnpm/@storybook/preset-create-react-app@3.1.5_9aa452dba90d1f953a1868926ff23f98/node_modules/@storybook/preset-create-react-app/dist/index.js:111:28)
ERR! at /home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/presets.js:259:28
ERR! at async startPreview (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/dev-server.js:407:23)
ERR! at async Promise.all (index 0)
ERR! at async storybookDevServer (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/dev-server.js:494:29)
ERR! at async buildDevStandalone (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-dev.js:317:33)
ERR! at async buildDev (/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-dev.js:380:3) {
ERR! code: 'MODULE_NOT_FOUND',
ERR! requireStack: [
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/preset-create-react-app@3.1.5_9aa452dba90d1f953a1868926ff23f98/node_modules/@storybook/preset-create-react-app/dist/index.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/presets.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/config.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/dist/server/build-static.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/core@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/core/server.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/dist/server/index.js',
ERR! '/home/node/x/app/node_modules/.pnpm/@storybook/react@6.1.10_react-dom@17.0.1+react@17.0.1/node_modules/@storybook/react/bin/index.js'
ERR! ]
ERR! }
WARN Broken build, fix the error above.
WARN You may need to refresh the browser.
System
+ sb 6.2.0-alpha.5
Environment Info:
System:
OS: Linux 5.3 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 14.15.1 - /usr/local/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.8 - /usr/local/bin/npm
npmPackages:
@storybook/addon-actions: ^6.1.10 => 6.1.10
@storybook/addon-essentials: ^6.1.10 => 6.1.10
@storybook/addon-links: ^6.1.10 => 6.1.10
@storybook/node-logger: ^6.1.10 => 6.1.10
@storybook/preset-create-react-app: ^3.1.5 => 3.1.5
@storybook/react: ^6.1.10 => 6.1.10
Additional context At first blush, it appears that the problem is that storybook can’t find the location of react-scripts.
Apparently, while npm symlinks node_modules/.bin/react-scripts, pnpm puts in place a hardlink. This messes with cra-config.ts, which can’t resolve the location of the package.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 187
- Comments: 60 (20 by maintainers)
Commits related to this issue
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
- chore: Drop `yarn2nix` and switch to `pnpm`. This is a wide-ranging change in which we drop `yarn2nix` (and Yarn itself) in favor using `pnpm` directly, with no Nix layer in-between the `pnpm` lockfi... — committed to hackworthltd/primer-app by dhess 2 years ago
The issue can be traced to this line: https://github.com/storybookjs/presets/blob/master/packages/preset-create-react-app/src/index.ts#L102
scriptsPathis the default/user/name/node_modules, which won’t work for pnpm. While not ideal, a workaround is to explicitly declare thescriptsPackageNameoption on the preset, which forces the code into theifblock that then usesrequire.resolveto resolve thereact-scriptspackage path appropriately via pnpm (https://github.com/storybookjs/presets/blob/master/packages/preset-create-react-app/src/index.ts#L67).The issue could potentially be resolved by defaulting
options.scriptsPackageNametoreact-scripts(rather than leavingoptions.scriptsPackageNameundefined).Workaround details:
In
.storybook/main.js, change:to:
Hope it at least helps someone get unblocked.
No worries! We know folks like using PNPM and I’m on a mission to make Storybook work correctly with it out of the box. It’s just been a bit tricky, is all, but we’re getting close.
change your pnpm to npm and works just fine
PNPM should be fully supported by Storybook now in the latest beta versions of 7.0. If you’re still experiencing any issues after updating with
pnpx sb@next upgrade --prerelease(or installing withpnpx sb@next init), please search to make sure there’s no issue already, then open a new issue with as many details as possible.Thanks for your patience, everyone. I’m excited that I’m one step closer to being able to use pnpm in my own projects now too!
I encountered this same problem. PNPM is the 3rd most popular package manager for Node.js. It has a huge user base, particularly for large corporate monorepos. What can we do to get PNPM support?
This should work:
npx sb init -s: Skip installation of dependencies on the initial scriptpnpm i: Install by yourselfAny news on this?
with
node-linker=hoistedit should worki just encountered the same problem +1
I’ve got it working I’m using
nx+pnpm workspaceswherestorybookis installed alongside avue3 + vitecomponent libraryBefore adding storybook, an
.npmrcfile must be added to the root to hoist storybook deps:You’ll have to
pnpm iagain after this changeThen follow the steps in this comment
When will we stop assuming
Any improvements in this?
The latest alpha version of storybook will now use pnpm to install dependencies when you run
npx sb@nextcommands.For those of you who were not able to install storybook at all (e.g. due to pnpm workspace), this should fix your issue. You can now run
npx sb@next init, and you’ll get the latest storybook 7 alpha version. Unfortunately I don’t think there’s a way to install storybook 6.5 that way, but I’d encourage you to try 7.0. It has many improvements, though there still may be some disruptive changes coming before the stable release.The other main pnpm issue is with the way storybook relies on hoisting. We’ve made some progress there, but are still working on it. For now, I think the best workaround is still to use
public-hoist-pattern[]=*storybook*, or to manually install the packages that pnpm complains about into your package.json.@gaetanmaisse just a mild soft ping for you here ❤️
Given that pnpm is now shipped with Node along side npm and yarn, and this issue is still valid, it’s probably wise to find someone on the team willing to pick it up.
@zkochan would any of the new options around hoisting/flat enable compatibility with storybook?
Nope, I am using Vue, I managed to work around the problem for now using a
.npmrcfile.Not ideal, but it works for now and it’s better than hoisting all of the modules.
Please let me know if you wish to test any future versions 👍
@IanVS I realised why the public-hoist-pattern doesn’t work for me. It’s not supported for workspace dependencies which is where Storybook is failing for me https://github.com/pnpm/pnpm/issues/3642.
Still going to try the alpha and see if there’s any improvement.
For me what it worked is:
npx sb init --type vue3 -spnpm install --shamefully-hoistSome workarounds can be found in https://github.com/storybookjs/storybook/issues/12995#issuecomment-813630999
Works great even with
pnpxcommand 😃 Thanks @IanVSAs for
npx sb init, I’ve opened https://github.com/storybookjs/storybook/pull/19425 which will detect when pnpm is in use in a project, and use it to install dependencies if so.@IPWright83 what error are you getting, and what framework are you using?
Besides installation, also build failed, so, you have to explicitly hoist such dependencies.
Example
.npmrcfor project:FYI, I looked at this today and am able to reproduce.
It seems to be an issue with with
@storybook/preset-create-react-app. When I run this with a vanilla react app usingsb@next, it works fine.I’ll see if I can figure out the fix for CRA this week!
@blowsie are you also using CRA?
Hey @IanVS, my issue is possibly slightly different but I thought I’d be bumped here if I raised a new one. It’s a pnpm monorepo with workspaces (though just 2 packages currently) using React.
It’s the
build-storybookscript hitting a module not foundSo it manifests in the same sort of way.
Slightly oddly is I can get it working locally fine (on Ubuntu) but it always fails on Windows and in CI where I’m trying to use https://github.com/storybookjs/storybook-deployer and it falls over delegating to the build-storybook call.
None of the workarounds except this one work for me, essentially disabled pnpms best feature :\
also have this problem, but if i remove
@storybook/preset-create-react-appfrom main.js it builds fine, only with warning aboutpreset-create-react-app