You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an npm packge published to the registry as TypeScript tries to import the classNames package (which is CommonJS), the following error occurs during vite:
Uncaught SyntaxError: The requested module '/node_modules/classnames/index.js?v=1c99386f' does not provide an export named 'default' (at index.tsx:1:8)
This error does not occur when the app is built using vite build.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
@hi-ogawa Thank you so much! You're right that the docs seem to indicate this isn't a bug, and is likely expected behavior. The only thing that confuses me is that sample-package isn't technically an ESM package, but I guess this is what happens when you do something silly like shipping TypeScript directly to npm.
Gonna leave this open, but would not be offended if this was closed as expected behavior.
I think this is a variation of #3910. Since sample-package publishes raw JSX, Vite's prebundling doesn't bundle the .jsx file (in favor of transpiling it later when used, so classnames was indirectly not prebundled too.
Unfortunately the problem is a bit hard to fix in Vite at the moment, and the explicit optimizeDeps.include config is the easiest way to workaround this at the moment. I'll close this for now in favour of the linked issue above so we track it in a single place.
Describe the bug
When an npm packge published to the registry as TypeScript tries to import the
classNames
package (which is CommonJS), the following error occurs duringvite
:This error does not occur when the app is built using
vite build
.Reproduction
https://github.com/dstaley/vite-classnames-import-bug
Steps to reproduce
npm run dev
npm run build
npx serve
works for this).System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: