Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: macos - Error: Cannot find module '.../node_modules/config/webpack.config' #242

Open
unional opened this issue Mar 24, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@unional
Copy link

unional commented Mar 24, 2022

Describe the bug

Unable to start storybook in MacOS when using with rush and pnpm

Steps to reproduce the behavior

Repro:

https://github.com/cyberuni/storybook-preset-mac-os/tree/cmd

You need to install rush for the repro (npm i -g @microsoft/rush and corepack enable)

rush install
cd just-func/just-react
rushx storybook

Expected behavior

storybook starts

Screenshots and/or logs

info => Loading Webpack configuration from `node_modules`
info => Removing existing JavaScript and TypeScript rules.
ERR! Error: Cannot find module '.../node_modules/config/webpack.config'

Environment

  • OS: MacOS 11.6.5
  • Node.js version: 16.14.2

Additional context

The problem is caused by this code:

https://github.com/storybookjs/presets/blob/master/packages/preset-create-react-app/src/helpers/getReactScriptsPath.ts#L37-L39

      const resolvedBinPath = realpathSync(scriptsBinPath);
      const scriptsPath = join(resolvedBinPath, '..', '..');
      return scriptsPath;

scriptsBinPath is something like .../node_modules/.bin/react-scripts
so going up two levels becomes .../node_modules

Changing it to join(resolvedBinPath, '..', '..', 'react-scripts') or removing that code will fix the issue.

The next block gets the correct path:

    const scriptsPath = dirname(require.resolve('react-scripts/package.json'));
    return scriptsPath;

What's the use case for that code? Can it be adjusted or removed?

@unional unional added the bug Something isn't working label Mar 24, 2022
@unional
Copy link
Author

unional commented Apr 12, 2022

I can repro it with just pnpm

@unional
Copy link
Author

unional commented May 3, 2022

This is similar to: storybookjs/storybook#10668

@carbon-intelligence
Copy link

This works fine for me on WIndows but see the error above in a Linux VM and Bitbucket pipeline using Docker. The source of the issue is definitely that getReactScriptsPath utility file.

@Asuka109
Copy link

I tried to modify the .storybook/main.js from:

module.exports = {
  addons: [
    '@storybook/preset-create-react-app'
  ]
};

to:

module.exports = {
  addons: [
    {
      name: '@storybook/preset-create-react-app'
      options: {
        scriptsPackageName: 'react-scripts'
      }
    }
  ]
};

And it is works for me.

@ollwenjones
Copy link

ollwenjones commented Dec 5, 2022

similar deal for me, where it works fine on windows, but not on mac. We have our own fork of react-scripts, but not storybook. About to try @Asuka109 's fix. seems to have worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants