-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Error: 'default' is not exported by..." when building with imported umd module #2679
Comments
The |
Hello! Thanks for trying it out. I was trying to fix the issue myself and found a solution for it yesterday. I had to add // vite.config.js
build: {
commonjsOptions: {
exclude: ['ckeditor/*'],
},
....
} Now it's working fine. I also restored the add-vite branch the way it was previously, in case you want to check out the problem. Unless this is a problem you'd like you track, this issue can be closed for now :) You can also observe the problem if you use the master branch and comment out the commonjsOptions |
I found the same problem with our private code base. Is this a bug or simply a necessary configuration step for vite? |
I notice linking. Try not to using linking, use |
I just stumbled upon this error when I updated vite from version 2.4 to 2.7. My error is caused by a named export and not a default export though. error during build:
Error: 'SharedArray' is not exported by ../shared-project/lib/index.js, imported by main-project/index.ts
at error (/workspace/pvs/client/node_modules/rollup/dist/shared/rollup.js:158:30)
at Module.error (/workspace/pvs/client/node_modules/rollup/dist/shared/rollup.js:12354:16) shared-project is a private package in my monorepo, that I symlinked using // main-project/package.json
"shared-project": "file:../shared-project", With vite version 2.4 my // old vite.config.ts
{
plugins: [vue()],
optimizeDeps: {
include: ['shared-project'],
},
build: {
commonjsOptions: { exclude: ['shared-project'] },
// commonjsOptions: { }, // Edit:
}, // I just realized, that this line of code would have been
} // sufficient. I didn't need the `exclude` from above. I
// guess that means I abused a bug, that was fixed now. With version 2.7 I get the error above. I tracked the breaking change down to this commit (#5111) from version 2.6, but I don't really understand why it's a breaking change. I just know, that when I include // new vite.config.ts
{
plugins: [vue()],
optimizeDeps: {
include: ['shared-project'],
},
build: {
commonjsOptions: { exclude: ['shared-project'], include: [] }, // <----
// commonjsOptions: { include: [] }, // Edit:
}, // This works just as well.
} Edit:It looks like I abused a bug before, that was now fixed. But I still don't understand why I can't use |
I'm also getting similar errors, for example: As @fardolieri suggested, adding |
This is now documented at https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies and is an expected configuration in Vite. However, there's a PR #7094 to improve this. |
Thanks for the update. while adding // optimizeDeps: { include:['my-pkg'] }
import {MyClass} from 'my-pkg'; // works
import {MyClass} from 'my-pkg/classes'; // Error: 'MyClass' is not exported by .... the issue is in this line which checks for literal string match.
Meanwhile - all imported paths needs to be added explicitly - e.g. |
Yeah, currently the paths have to be added manually. That would be a feature request though (not sure if there's an existing one). I too have had usecases which a feature like that would help. It would be a matter of globbing the files to be optimized using the regex/glob (I think glob syntax is prefered), as those files will be added as entrypoints for esbuild to prebundle. |
Describe the bug
I'm trying to use CKEditor in my project. They distribute the editor as a UMD module and I'm linking it to my project using npm workspaces. When I import the module in my code, I get the following error in the browser console when running the dev server:
I resolved that issue by setting:
However, when I try to do a production build, I get a similar error during the build process:
I would expect the production build to work since the dev build work perfectly fine.
I'm having a hard time figuring out why this is happening and any help would be appreciated!
Reproduction
You can clone my repo and build it. The issue will be apparent:
https://github.com/TheSimpleZ/kookbook
Use the
add-vite
branch, runnpm i
and thennpm run build
. Runningnpm run dev
works perfectly fine.System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Logs
Logs with the debug flag are quite long and will probably make this post hard to read.
The most relevant parts are shown above. If you need more details, please use the repo I linked.
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: