In our app we are using absolute paths for import modules. We have react
folder into our resolve root:
We are using webpack for build and develop app and it works ok, with the next options:
resolve: {
modules: [
'node_modules',
path.resolve('src')
]
},
I'm working on integration of storybook and found, that it can't find any module from this react
folder.
ERROR in ./stories/index.stories.js
Module not found: Error: Can't resolve 'react/components/Button' in 'project_name/stories'
@ ./stories/index.stories.js
for the next line: import Button from 'react/components/Button';
As mark: I added resolve/modules to.storybook/webpack config and also if I try to import anything other from, for example services/xxx
- it works.
react
folder name conflicts with actual React package location: node_modules/react
. Webpack tries to resolve to .resolution
(default is node_modules
) if the file does not exist in the path..resolution
is not appropriate for this sort of usage. it is mostly used for package resolution because it can't tell source strings.alias
instead .node_modules/react
. a good example is view/components/Button
..storybook/main.js
setting// .storybook/main.js
const path = require('path');
module.exports = {
/* ... other settings goes here ... */
/**
* @param {import('webpack').Configuration} config
* */
webpackFinal: async (config, { configType }) => {
if (!config.resolve) config.resolve = {};
// this config allows to resolve `view/...` as `src/view/...`
config.resolve.alias = {
...(config.resolve.alias || {}),
view: path.resolve(__dirname, '../src/view'),
};
return config;
},
};
// Button.stories.jsx
import Button from 'view/components/Button';
//...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.