storybook: [Bug]: Vite CJS warning still present in v8 RC
Describe the bug
Using Vite 5 with Storybook 8 RC produces the following warning:
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details
According to #24333 this was supposed to be fixed with v8. As a RC has been released, I would assume this should have been fixed by now.
To Reproduce
https://github.com/dan-mba/react-svg-components/tree/sb-8
System
Storybook Environment Info:
System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v20.11.1/bin/yarn
npm: 10.4.0 - ~/.nvm/versions/node/v20.11.1/bin/npm <----- active
pnpm: 8.7.0 - ~/.nvm/versions/node/v20.11.1/bin/pnpm
Browsers:
Chrome: 122.0.6261.94
npmPackages:
@storybook/addon-essentials: ^8.0.0-rc.1 => 8.0.0-rc.1
@storybook/react: ^8.0.0-rc.1 => 8.0.0-rc.1
@storybook/react-vite: ^8.0.0-rc.1 => 8.0.0-rc.1
eslint-plugin-storybook: ^0.8.0 => 0.8.0
storybook: ^8.0.0-rc.1 => 8.0.0-rc.1
Additional context
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 19
- Comments: 20 (7 by maintainers)
i still get the warning when using:
@JReinhold The dynamic import got rid of the warning for me.
The sample
main.js|tsin the Vite Configuration Docs will cause the same warning. Adding a mention about dynamic import here would be useful.It might also be nice to have a warning when using the update migration cli.
** Disclaimer** This information might be inaccurate, due to it being generated automatically To address the Vite CJS warning in Storybook 8 RC, update the Vite configuration to use the ESM build of Vite’s Node API. Modify the
vite.config.tsfile in the/code/builders/builder-vite/srcdirectory as follows:Ensure that the
vitedependency inpackage.jsonis updated to a version that supports ESM:References
/.github/DISCUSSION_TEMPLATE/help.yml /code/builders/builder-vite/README.md /code/lib/cli/src/automigrate/fixes/addon-postcss.ts /code/lib/cli/src/autoblock/block-storystorev6.ts /code/lib/cli/src/automigrate/fixes/cra5.ts /code/lib/cli/src/automigrate/fixes/vue3.ts /code/lib/cli/src/automigrate/fixes/prompt-remove-react.ts /code/core/src/server-errors.ts /.github/comments/invalid-link.md /code/lib/cli/src/automigrate/fixes/angular-builders.ts /code/frameworks/svelte-vite/README.md /code/frameworks/angular/src/builders/build-storybook/schema.json /docs/versions/next.json /docs/get-started/frameworks/react-vite.mdx /code/lib/cli/src/automigrate/fixes/angular-builders-multiproject.ts /code/builders/builder-vite /code/builders/builder-vite/package.json /code/lib/cli/src/automigrate/fixes/builder-vite.test.ts /code/lib/cli/src/automigrate/fixes/builder-vite.ts /docs/get-started/frameworks/svelte-vite.mdx /code/lib/cli/src/automigrate/fixes/webpack5-compiler-setup.ts /code/lib/cli/src/automigrate/fixes/storyshots-migration.ts /code/lib/csf-plugin /code/deprecated/components/package.json /code/renderers/svelte/package.json
About Greptile
This response provides a starting point for your research, not a precise solution.
Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Ask Greptile · Edit Issue Bot Settings
If users are importing from Vite in their main config like @dan-mba is in their reproduction, they need to use a dynamic import instead of a top-level import to silence this warning, like this:
This is not trivial to fix for us internally as it requires that we make changes to our preset loading, something @ndelangen is hesitant about and definitely won’t happen for 8.0 GA. I think @ndelangen’s hope is to do this as part of the ESM transition?
We could perhaps document this dynamic import requirement though? @kylegach
Upon tracing the origin of the CJS warning, I identified its source in the file:
node_modules/vite-plugin-istanbul/dist/index.cjs:It’s worth noting that upon the comment of @wuifdesign, I also removed reactDocgen: “react-docgen-typescript”, as it was another trigger for the warning message. As evidenced in this screenshot, the warning comes from
node_modules\@joshwooding\vite-plugin-react-docgen-typescript\dist\index.cjs:3:The warning ceased to appear after the removal of both
@storybook/addon-coverageandreact-docgen-typescript.Both files share the same import statement:
const vite = require('vite');This import seems to be the culprit behind the warning. Based on my understanding from https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated, it appears that vite should be imported dynamically.
Update:
Upon examination of the
vite-plugin-react-docgen-typescript, it appears that the issue has been addressed in version 0.3.1, as evidenced by the changes documented here.In our project, we resolved this by explicitly setting the version in the package.json file:
However, it’s worth noting that the issue persists in the
vite-plugin-istanbulproject. They continue to utilize the normal import for vite, as illustrated here.I have opened a ticket for that: https://github.com/iFaxity/vite-plugin-istanbul/issues/209
@vanessayuenn It’s not solved yet for this case:
@JReinhold I tried it, but this doesn’t help either. Same error. Here’s the trace, if this is helpful:
I actually just realized that Vite offers an escape hatch for suppressing the warning (
VITE_CJS_IGNORE_WARNING=true) so that will unblock me for now. It sounds like this issue will eventually get fixed in Storybook, based on the comments above. Just as long as it gets fixed before Vite removes the CJS API entirely. 😄Looks like this issue has been resolved upstream, so closing this now. Let me know if this isn’t the case!