question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with pnpm

See original GitHub issue

Describe the bug Installation with pnpm doesn’t work.

To Reproduce Steps to reproduce the behavior:

In a new folder…

  1. pnpx create-react-app app
  2. cd app
  3. pnpx sb-init
  4. rm -rf node_modules
  5. pnpm i
  6. pnpm 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:165
  • Comments:50 (18 by maintainers)

github_iconTop GitHub Comments

47reactions
kaidjohnsoncommented, Jan 4, 2021

The issue can be traced to this line: https://github.com/storybookjs/presets/blob/master/packages/preset-create-react-app/src/index.ts#L102

scriptsPath is the default /user/name/node_modules, which won’t work for pnpm. While not ideal, a workaround is to explicitly declare the scriptsPackageName option on the preset, which forces the code into the if block that then uses require.resolve to resolve the react-scripts package 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.scriptsPackageName to react-scripts (rather than leaving options.scriptsPackageName undefined).

Workaround details:

In .storybook/main.js, change:

  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/preset-create-react-app"
  ]

to:

  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    {
      name: "@storybook/preset-create-react-app",
      options: {
        scriptsPackageName: 'react-scripts'
      }
    }
  ]

Hope it at least helps someone get unblocked.

42reactions
grinsteindavidcommented, Jul 1, 2022

change your pnpm to npm and works just fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently Asked Questions - PNPM
pnpm does not work with <YOUR-PROJECT-HERE>?​. In most cases it means that one of the dependencies require packages not declared in package.json ....
Read more >
How to fix "postbuild" and "prebuild" not working with pnpm?
I found out this issue on Github mentionning the same problem I encountered. It seems that pre/posts scripts are not activated if using...
Read more >
pnpm/pnpm - Gitter
Is anyone else having issues with pnpm and nextjs/react? Up until recently, I could easily use pnpm init next-app , blow away the...
Read more >
[pnpm] Code Completion and indexing does not work
The problem either occurs because of the symbolic links pnpm uses or because the pnpm-store is also part of the IntelliJ project in...
Read more >
PNPM - Starting new project not working as expected
pnpm used to have issues with React Native. pnpm uses symlinks a lot and React Native doesn't like symlinks. P.S. if you don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found