Open NTC-THSTO opened 3 months ago
Hi, thanks for reporting this. The code snippets you provided don't seem to match the error message you shared, so it's difficult to understand what's wrong. Can you please create a repro via storybook.new? We prioritize bug reports that have reproduction. Thank you! 🙏
Also getting similar issue:
@ ./storybook-stories.js 23:11-27:5
@ ./storybook-config-entry.js 6:0-50 18:31-39 25:2-28:4 25:58-28:3 27:31-39
ERROR in ./.storybook/preview.jsx 86:6
Module parse failed: Unexpected token (86:6)
File was processed with these loaders:
* ../../../node_modules/@storybook/preset-react-webpack/dist/loaders/react-docgen-loader.js
SB_BUILDER-WEBPACK5_0003 (WebpackCompilationError): There were problems when compiling your code with Webpack.
Run Storybook with --debug-webpack for more information.
You may need an additional loader to handle the result of these loaders.
`
I also raised the next package version to 15 and migrated the reaction to 18 and got the same error. And Can't resolve '@swc/helpers/_/_tagged_template_literal' in
ERROR in ./src/styles/GlobalStyle.tsx 3:0-88
Module not found: Error: Can't resolve '@swc/helpers/_/_tagged_template_literal' in '/Users/jupi/Project/healingpaper/web-frontend/webViews/personalization/src/styles'
@ ./.storybook/preview.tsx 6:0-52 71:22-33
@ ./storybook-config-entry.js 11:1965-2069 32:2-35:4 32:1953-35:3
preview compiled with 13 errors
=> Failed to build the preview
99% end closing watch compilationWARN Force closed preview build
SB_BUILDER-WEBPACK5_0003 (WebpackCompilationError): There were problems when compiling your code with Webpack.
Run Storybook with --debug-webpack for more information.
at starter (/Users/jupi/Project/healingpaper/web-frontend/node_modules/@storybook/builder-webpack5/dist/index.js:1:8088)
at starter.next (<anonymous>)
at Module.start (/Users/jupi/Project/healingpaper/web-frontend/node_modules/@storybook/builder-webpack5/dist/index.js:1:10083)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I made a version of storybook 7 and solved it
I have the same problem, is there a solution to fix it?
Hi @NTC-THSTO
Thank you for reporting this issue.
The problem is that you import a file from node_modules, which isn't compiled into normal JavaScript. Instead, it is still written in TypeScript. Storybook's webpack loaders usually don't transform files in node_modules for performance reasons.
I see, that you tried to set up a ts-loader
yourself, but actually you have excluded node_modules. That's the reason why the ts-loader
doesn't have any effect.
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/, // <- This prevents the transformation of e.g. ./node_modules/@amplio/core/core/components/Alert/index.tsx
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
};
You could try to tweak your webpack config or tweak Storybooks webpack config by providing a webpackFinal configuration.
// .storybook/main.js|ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
+ webpackFinal: async (config, { configType }) => {
+ config.module?.rules?.push({
+ test: /\.tsx?$/,
+ use: 'ts-loader',
+ exclude: /node_modules(?!\/@amplio)/,
+ })
};
export default config;
By using the /node_modules(?!\/@amplio)/
exclude pattern, only files in the @amplio
node_modules folder get transformed, ignoring all the other node_modules for performance reasons. I would also advice you to use babel-loader
instead of ts-loader
, because that's what Storybook does internally to transform your files.
I encountered same issue. It is worth noting that babel has been moved out as part of major v8 upgrade, and you will need to set up by yourself.
For me, install @storybook/addon-webpack5-compiler-babel
and @babel/preset-env
, @babel/preset-react
, setup .babelrc.js
file, then the issue gone.
I encountered same issue. It is worth noting that babel has been moved out as part of major v8 upgrade, and you will need to set up by yourself.
For me, install
@storybook/addon-webpack5-compiler-babel
and@babel/preset-env
,@babel/preset-react
, setup.babelrc.js
file, then the issue gone.
I just get this when I try that
ERROR in ./config/storybook/preview.tsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: [BABEL]: _lruCache is not a constructor (While processing: /.../node_modules/@babel/preset-env/lib/index.js)
Same issues here, specifically when I am trying to set up React Server Components
this helped me
babel setting
"babel": { "presets": [ "@babel/preset-env", "@babel/preset-react" ] },
npm i -D @storybook/addon-webpack5-compiler-swc
or with automatically setting the file main.ts storybook info
npx storybook@latest add @storybook/addon-webpack5-compiler-swc
file .storybook/main.ts
import type { StorybookConfig } from "@storybook/react-webpack5";
const config: StorybookConfig = {
addons: [
...
"@storybook/addon-webpack5-compiler-swc"
],
framework: {
name: "@storybook/react-webpack5",
...
options: {
builder: {
useSWC: true,
},
},
...,
},
};
export default config;
The useSWC flag isn't necessary in Storybook 8 anymore.
babel/preset-env
@eric-blue what did you mean by setting up .babelrc?
I encounter this error when I try to install storybook to an existing React Project that uses Rollup, any ideas guys?
I encounter this error when I try to install storybook to an existing React Project that uses Rollup, any ideas guys?
same, did you fix that ?
@vanessayuenn
Another option for reproducing this:
yarn install
yarn task --task sandbox --start-from auto --template angular-cli/default-ts
cd sandoox/angular-cli-default-ts
yarn storybook
SB_BUILDER-WEBPACK5_0003 (WebpackCompilationError): There were problems when compiling your code with Webpack.
Run Storybook with --debug-webpack for more information.
at starterGeneratorFn (./node_modules/@storybook/builder-webpack5/dist/index.js:316:11)
at starterGeneratorFn.next (<anonymous>)
at Module.start (./node_modules/@storybook/builder-webpack5/dist/index.js:396:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
If someone trying to setup Gatsby 5 with Storybook 8 and wants to use @storybook/addon-webpack5-compiler-babel
I just created a fresh Gatsby App and installed SB with npx storybook@latest init
Had to reaplace @storybook/addon-webpack5-compiler-swc
with @storybook/addon-webpack5-compiler-babel
My Webpack Config in main.ts
looks like this
webpackFinal: async (config: any) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { typescript: true }]],
},
})
return config
},
Packages:
"dependencies": {
"gatsby": "^5.13.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@chromatic-com/storybook": "^1.5.0",
"@storybook/addon-essentials": "^8.1.6",
"@storybook/addon-interactions": "^8.1.6",
"@storybook/addon-links": "^8.1.6",
"@storybook/addon-onboarding": "^8.1.6",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@storybook/react": "^8.1.6",
"@storybook/react-webpack5": "^8.1.6",
"@types/node": "^20.11.19",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"babel-preset-react-app": "^10.0.1",
"storybook": "^8.1.6",
"typescript": "^5.3.3"
}
I get the same error. I'm trying to upgrade from v7 to v8. Our Storybook main and preview files are in TS format, and I get the error when it tries to process the preview.ts file. Almost seems like it's no longer recognizing my babel config which includes @babel/preset-react
, @babel/preset-typescript
and others.
Also, I'm in a monorepo if that makes any difference.
EDIT: I confirmed it's not recognizing my babel config file any more. As per this note in the doc, running:
BABEL_SHOW_CONFIG_FOR=path/to/my/preview.ts storybook dev ...
I see:
{
"babelrc": false,
"configFile": false,
"filename": "/full/path/to/my/preview.ts"
}
Which is incorrect, I have a babel.config.js file defined in my package root. So in my case perhaps this is all due to the babel issue.
If someone trying to setup Gatsby 5 with Storybook 8 and wants to use
@storybook/addon-webpack5-compiler-babel
I just created a fresh Gatsby App and installed SB with
npx storybook@latest init
Had to reaplace
@storybook/addon-webpack5-compiler-swc
with@storybook/addon-webpack5-compiler-babel
My Webpack Config in
main.ts
looks like thiswebpackFinal: async (config: any) => { config.module.rules.push({ test: /\.(ts|tsx)$/, loader: require.resolve('babel-loader'), options: { presets: [['react-app', { typescript: true }]], }, }) return config },
Packages:
"dependencies": { "gatsby": "^5.13.5", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@chromatic-com/storybook": "^1.5.0", "@storybook/addon-essentials": "^8.1.6", "@storybook/addon-interactions": "^8.1.6", "@storybook/addon-links": "^8.1.6", "@storybook/addon-onboarding": "^8.1.6", "@storybook/addon-webpack5-compiler-babel": "^3.0.3", "@storybook/react": "^8.1.6", "@storybook/react-webpack5": "^8.1.6", "@types/node": "^20.11.19", "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19", "babel-preset-react-app": "^10.0.1", "storybook": "^8.1.6", "typescript": "^5.3.3" }
I have already found, that is only working until you use Gatsby Link. currently debugging.
my guess is also that it has something to do with webpack and babel config.
in SB8 they implemented @storybook/addon-webpack5-compiler-babel
, maybe there are some problems.
I have found a working version with Storybook 8 and Gatsby 5.
I have created a starter with the needed config/settings: https://github.com/paulgrotzke/gatsby5-storybook8
For what it's worth, SB_BUILDER-WEBPACK5_0003
seems to be a catchall for any Webpack error that occurs while building storybook. I found it helpful to get more specific errors by...
--debug
flag, as shown in the original reportIn my case, the webpack error was:
Module build failed (from ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js):
Error: [BABEL] ./node_modules/@angular/compiler/fesm2022/compiler.mjs: Cannot find module '@babel/helper-replace-supers'
The Storybook doctor error was:
Attention: The following dependencies are duplicated which might cause unexpected behavior:
@storybook/types: 7.6.20, 7.6.17
@storybook/channels: 7.6.20, 7.6.17
@storybook/core-events: 7.6.20, 7.6.17
I had an old plugin that was pulling in an extra copy of Storybook. I used yarn resolutions to deduplicate the dependency, which resolved the Webpack error.
Describe the bug
running yarn storybook --debug-webpack does not build once I have imported ts files.
To Reproduce
main.js
story
package.json
System
No response
Additional context
This error only occurs once trying to import files.
I have tried using a webconfig but this also had the same issues.
We have no issue using this import method in any other implementations of our components, leading me to believe its a storybook issue