Replies: 3 comments 1 reply
-
Start a new pull request in StackBlitz Codeflow. |
Beta Was this translation helpful? Give feedback.
-
CryptoJS is written in CJS. It needs to be processed by commonjs plugin. import { defineConfig } from 'vite';
export default defineConfig({
optimizeDeps: {
include: [],
},
build: {
commonjsOptions: {
include: [/\/crypto-js\//],
},
},
}); |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer. While that solves my problem, I still think it is a bug and doesn't belong in Q&A. In my code example on stackblitz, if you delete the whole |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I added vjsf to my project which relies on some CommonJS depencies. So in order to make it work i added this to my vite.config.js:
My application now runs in dev, but when i run npm run build (vite build --force) I get the
"default" is not exported by ...
error on unrelated packages.For example crypto-js which was in my project before I added vjsf and the commonjsoptions now breaks my build pipeline:
While importing
it like in line 3 below would work for this particular library, the wildcard import does not work for other packages (vue3-markdown-it which i use in my .vue files). So I don't want the wildcard as a fix as it doesn't work with all my libraries, but rather want to understand why this happens and how I can prevent it from happening broadly.
Reproduction
https://stackblitz.com/edit/vitejs-vite-klru7e?file=vite.config.js
Steps to reproduce
Run
npm install
. Then trynpm run build
. It will fail with the CryptoJS import error.Try it again after in the vite.config.js deleting
How does this make a difference?
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
Beta Was this translation helpful? Give feedback.
All reactions