Storybook: Run storybook with custom NODE_PATH

Created on 19 Jul 2016  路  2Comments  路  Source: storybookjs/storybook

Hello,

Im trying to set up react-storybook in a project that I'm working on. They are using better-npm-run with custom NODE_PATH, so what I tried is setting up the same way react-storybook:

"betterScripts": {
    "storybook": {
      "command": "start-storybook -p 9001",
      "env": {
        "NODE_PATH": "./src"
      }
    }
  }

But storybook is not picking up the new path like:

I have a component:

project/src/components/MyComponent.js
is importing
import Bar from 'components/Others/Bar';

and I got

ERROR in ./src/components/MyComponent.js
Module not found: Error: Cannot resolve module 'components/Others/Bar' ...
looking for modules in /Users/msaglietto/Projects/project/node_modules
/Users/msaglietto/Projects/project/node_modules/components doesn't exist (module as directory)

Is something that prevent me to use the custom NODE_PATH? or should I configure it elsewhere?

discussion

Most helpful comment

Hey @mnmtanish, thanks it worked. I used:

resolve: {
    root: [
      path.resolve(__dirname, '../src'),
    ]
  }

or path.resolve(__dirname, '..', process.env.NODE_PATH) if you want to keep using the NODE_PATH

All 2 comments

Hi @msaglietto
I think you're looking for this. Add a webpack config file as explained here and set resolve.root to your src directory. I haven't tried it but I think it should work. Let us know how it goes :)

Hey @mnmtanish, thanks it worked. I used:

resolve: {
    root: [
      path.resolve(__dirname, '../src'),
    ]
  }

or path.resolve(__dirname, '..', process.env.NODE_PATH) if you want to keep using the NODE_PATH

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shilman picture shilman  路  3Comments

xogeny picture xogeny  路  3Comments

Jonovono picture Jonovono  路  3Comments

ZigGreen picture ZigGreen  路  3Comments

purplecones picture purplecones  路  3Comments