Storybook is not able to resolve path with Next js absolute import
See original GitHub issueDescribe the bug Storybook is not able to resolve path with Next js absolute import
To Reproduce Steps to reproduce the behavior: yarn add storybook Added .storybook folder Add jsconfig for absolute import
Expected behavior It should build correctly.
const path = require('path');
const resolve = (dir) => path.resolve(__dirname, dir);
module.exports = ({ config }) => {
config.resolve.alias = {
'@utils/*': resolve('../src/utils/*'),
....
};
return config;
};
Error
ERROR in ./src/components/Base/Button/Button.jsx
Module not found: Error: Can't resolve '@utils/boxShadowGenerator' in '/Users/rahulshrivastava/projects/unacademy-web-learning/src/components/Base/Button'
@ ./src/components/Base/Button/Button.jsx 9:0-59 107:35-53 122:9-27
@ ./src/stories/button.stories.js
@ ./src/stories sync \.stories\.js$
@ ./.storybook/config.js
@ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true&quiet=true
Code snippets I am using jsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"jsx": "react",
"baseUrl": "./src/",
"paths": {
"@utils/*": ["utils/*"],
....
}
},
"exclude": ["node_modules", "dist"]
}
System:
npx -p @storybook/cli@next sb info
Environment Info:
(node:1828) UnhandledPromiseRejectionWarning: TypeError: e.filter is not a function
at /Users/rahulshrivastava/.npm/_npx/1031/lib/node_modules/@storybook/cli/node_modules/envinfo/dist/envinfo.js:1:73205
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 6)
(node:1828) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1828) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:31 (11 by maintainers)
Top Results From Across the Web
Storybook with absolute paths - Stack Overflow
I got this issue after using CLI and I was able to resolve it by modifying my .storybook/main.js to: const path = require('path'); ......
Read more >Storybook is not able to resolve path with Next js absolute ...
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >How to resolve a path alias in Storybook - +return
The solution. To solve this issue, we will need to configure Storybook's webpack to resolve the path alias. the concept is really similar...
Read more >Storybook Addon Next
A no config Storybook addon that makes Next.js features just work in Storybook. ... Sass/Scss; Css/Sass/Scss Modules; Styled JSX; Postcss; Absolute Imports ......
Read more >[Solved]-Storybook with absolute paths-Reactjs
Related Query · Storybook with absolute paths · Jest gives `Cannot find module` when importing components with absolute paths · Resolve Absolute /...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Its because thats not an absolute import from root, your path is using an alias. The following code allows you to import from src using “src/components/button/Button”:
But it does not tell webpack anything about the “@/Components” syntax. You would need to pass an alias configuration like this:
I havent gotten everything working with Next yet but this resolved the absolute import issues (in .storybook/webpack.config.js):
For using ./src, you can use path.resolve(__dirname, “…”, “src”),