Open daviddelusenet opened 1 year ago
Any updates on this?
Probably not related, but you don't need new TsconfigPathsPlugin
, since @storybook/next
already handles that.
I am also getting the same error in the addon-storysource
package:
My setup:
"@storybook/addon-a11y": "7.4.6",
"@storybook/addon-actions": "7.4.6",
"@storybook/addon-controls": "7.4.6",
"@storybook/addon-docs": "7.4.6",
"@storybook/addon-essentials": "7.4.6",
"@storybook/addon-storysource": "7.4.6",
"@storybook/addons": "7.4.6",
"@storybook/api": "7.4.6",
"@storybook/components": "7.4.6",
"@storybook/core-events": "7.4.6",
"@storybook/react": "7.4.6",
"@storybook/react-webpack5": "7.4.6",
"@storybook/theming": "7.4.6",
main.js file:
import { dirname, join } from 'path';
// Case Sensitive partial filename of Story
const storyName = process.argv[6];
const stories = storyName
? `../src/**/?(*)${storyName}?(*).stories.{mdx,tsx}`
: '../src/**/*.stories.{mdx,tsx}';
module.exports = {
addons: [
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-actions'),
getAbsolutePath('@storybook/addon-docs'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-controls'),
getAbsolutePath('@storybook/addon-storysource'),
getAbsolutePath('storybook-dark-mode'),
],
framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
features: {
postcss: false,
storyStoreV7: false,
},
staticDirs: ['../public'],
stories: [stories],
};
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
Error log:
node_modules/@storybook/addon-storysource/preset.js:1
import './dist/preset';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1124:15)
at Module._compile (node:internal/modules/cjs/loader:1160:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
I want to report I am getting a similar error with "@storybook/addon-storysource": "^7.5.2",
so this error is still present in the latest version. There is an issue with the import statement inside of storysource preset.js
Here is my config:
/** @type { import('@storybook/nextjs').StorybookConfig } */
const config = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-storysource'), //<---------------commenting this out and storybook builds correctly
getAbsolutePath('@etchteam/storybook-addon-status'),
{
name: '@storybook/addon-styling',
options: {
// Check out https://github.com/storybookjs/addon-styling/blob/main/docs/api.md
// For more details on this addon's options.
postCss: {
implementation: require.resolve('postcss'),
},
},
},
getAbsolutePath('@storybook/addon-themes'),
getAbsolutePath('@storybook/addon-mdx-gfm'),
],
framework: {
name: getAbsolutePath('@storybook/nextjs'),
options: {},
},
docs: {
autodocs: 'tag',
},
};
export default config;
here's the current versions of my deps I am using:
"@etchteam/storybook-addon-status": "^4.2.4",
"@storybook/addon-a11y": "^7.5.2",
"@storybook/addon-essentials": "7.5.1",
"@storybook/addon-interactions": "7.5.1",
"@storybook/addon-links": "7.5.1",
"@storybook/addon-mdx-gfm": "7.5.1",
"@storybook/addon-onboarding": "1.0.8",
"@storybook/addon-storysource": "^7.5.2",
"@storybook/addon-styling": "1.3.7",
"@storybook/addon-themes": "7.5.1",
"@storybook/blocks": "7.5.1",
"@storybook/nextjs": "7.5.1",
"@storybook/react": "7.5.1",
"@storybook/testing-library": "0.2.2",
Here are the relvant parts of the trace:
SB_CORE-SERVER_0002 (CriticalPresetLoadError):
Storybook failed to load the following preset:
my-project/node_modules/@storybook/addon-storysource/preset.js.
/my-project/node_modules/@storybook/addon-storysource/preset.js:1
import './dist/preset';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1153:20)
at Module._compile (node:internal/modules/cjs/loader:1197:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
at Object.newLoader (/my-project/node_modules/esbuild-register/dist/node.js:2262:9)
at extensions..js (/my-project/node_modules/esbuild-register/dist/node.js:4838:24)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:119:18)
Here's the exact line in the source code: https://github.com/storybookjs/storybook/blob/next/code/addons/storysource/preset.js#L1 , on the next
branch.
I am also receiving the same error.
$ yarn storybook
@storybook/cli v7.5.3
SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: .\.storybook\main.js.
Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.
If you believe this is a bug, please open an issue on Github.
SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: E:\Projects\Personal\monorepo\node_modules\@storybook\addon-storysource.
Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.
If you believe this is a bug, please open an issue on Github.
SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: E:\Projects\Personal\monorepo\node_modules\@storybook\addon-storysource\preset.js.
Please check whether your setup is correct, the Storybook dependencies (and their peer dependencies) are installed correctly and there are no package version clashes.
If you believe this is a bug, please open an issue on Github.
E:\Projects\Personal\monorepo\node_modules\@storybook\addon-storysource\preset.js:1
import './dist/preset';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1149:20)
at Module._compile (node:internal/modules/cjs/loader:1190:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Object.newLoader (E:\Projects\Personal\monorepo\node_modules\esbuild-register\dist\node.js:2262:9)
at extensions..js (E:\Projects\Personal\monorepo\node_modules\esbuild-register\dist\node.js:4838:24)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Module._load (node:internal/modules/cjs/loader:930:12)
at Module.require (node:internal/modules/cjs/loader:1113:19)
at require (node:internal/modules/cjs/helpers:103:18)
at loadPreset (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:82)
at loadPreset (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:82)
at async Promise.all (index 4)
at async loadPresets (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:505)
at async loadPreset (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:13:1025)
at async Promise.all (index 1)
at async loadPresets (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:505)
at async getPresets (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:1525)
at async buildDevStandalone (E:\Projects\Personal\monorepo\node_modules\@storybook\core-server\dist\index.js:119:1599)
at async withTelemetry (E:\Projects\Personal\monorepo\node_modules\@storybook\core-server\dist\index.js:103:3903)
at async dev (E:\Projects\Personal\monorepo\node_modules\@storybook\cli\dist\generate.js:473:401)
at loadPreset (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:82)
at async Promise.all (index 1)
at async loadPresets (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:505)
at async getPresets (E:\Projects\Personal\monorepo\node_modules\@storybook\core-common\dist\index.js:15:1525)
at async buildDevStandalone (E:\Projects\Personal\monorepo\node_modules\@storybook\core-server\dist\index.js:119:1599)
at async withTelemetry (E:\Projects\Personal\monorepo\node_modules\@storybook\core-server\dist\index.js:103:3903)
at async dev (E:\Projects\Personal\monorepo\node_modules\@storybook\cli\dist\generate.js:473:401)
at async Command.<anonymous> (E:\Projects\Personal\monorepo\node_modules\@storybook\cli\dist\generate.js:475:225)
WARN Broken build, fix the error above.
WARN You may need to refresh the browser.
WARN Failed to load preset: {"name":"E:\\Projects\\Personal\\monorepo\\node_modules\\@storybook\\addon-storysource\\preset.js"} on level 2
E:\Projects\Personal\monorepo\node_modules\@storybook\addon-storysource\preset.js:1
import './dist/preset';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1149:20)
at Module._compile (node:internal/modules/cjs/loader:1190:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Object.newLoader (E:\Projects\Personal\monorepo\node_modules\esbuild-register\dist\node.js:2262:9)
at extensions..js (E:\Projects\Personal\monorepo\node_modules\esbuild-register\dist\node.js:4838:24)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Module._load (node:internal/modules/cjs/loader:930:12)
at Module.require (node:internal/modules/cjs/loader:1113:19)
at require (node:internal/modules/cjs/helpers:103:18)
main.js
const { dirname, join, resolve } = require('path');
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
// Commenting the below out or just using the string without getAbsolutePath seems to work
getAbsolutePath('@storybook/addon-storysource'),
getAbsolutePath('storybook-dark-mode'),
getAbsolutePath('storybook-addon-mock'),
...(process.env?.TRANSPILER === 'swc'
? [getAbsolutePath('storybook-addon-swc')]
: [])
],
framework: {
name: getAbsolutePath('@storybook/nextjs'),
options: {}
},
webpackFinal: async config => {
// 👈 and add this here
config.resolve.alias = {
...config.resolve.alias,
'@': resolve(__dirname, '../src/')
};
return config;
},
docs: {
autodocs: true
}
};
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
package.json
{
...
"devDependencies": {
"@storybook/addon-a11y": "^7.5.3",
"@storybook/addon-actions": "^7.5.3",
"@storybook/addon-docs": "^7.5.3",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
"@storybook/addon-storysource": "^7.5.3",
"@storybook/nextjs": "^7.5.3",
"@storybook/react": "^7.5.3",
"@storybook/testing-library": "^0.2.2",
"storybook": "7.5.3",
"storybook-addon-mock": "^4.3.0",
"storybook-addon-swc": "^1.2.0",
"storybook-dark-mode": "^3.0.1",
}
...
}
It's also worth noting that in checking the preset.js files of all my other addons if one exists, it does not use import, but rather module.exports or requires, so it's commonjs. Is this just not getting transpiled correctly before packaging?
In my experience, you can remove the getAbsolutePath
and it will work:
- getAbsolutePath('@storybook/addon-storysource'),
+ '@storybook/addon-storysource',
Describe the bug
Hello everyone!
My project is monorepo setup with Turborepo. The structure of the project is the following
In the
ui
package is where my Storybook installation lives. Today I decided to start the migration from Storybook 6 to version 7.After the migration I get the following error when running
storybook dev
:This is my how my Storybook
main.js
files look like:One thing I'm sure about, it's not related to the Vanilla-Extract setup because the error was already happening before I added that.
When I just remove the
getAbsolutePath('@storybook/addon-storysource')
everything works fine.Does anyone have any idea on how to fix this?
Please let me know if you need any more information and thanks in advance!
To Reproduce
No response
System
Additional context
No response