-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[ES Module but shipped in a CommonJS package] Lib importing another ESM-only library #6875
Comments
Vitest cannot process ES modules that were imported using |
To bypass that, you can enable the optimizer: export default defineConfig({
test: {
deps: {
web: {
enabled: true,
include: ['lib'],
},
},
},
}) |
Hey @sheremet-va , thank you for responding. I tried applying it and it also didn't work |
@varugasu Assuming your |
Also what is the reason you have "exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./*": {
"require": "./dist/*/index.cjs",
"import": "./dist/*/index.mjs",
"types": "./dist/*/index.d.ts"
}
}, |
@hi-ogawa , the actual package is an internal one, so I can't share it. About your suggestion, it indeed solves my reproduction, but testing on my actual project, I have the following error:
(I redacted the sensitive information with I added
|
From what I can tell, both That said, the error from |
Describe the bug
I was creating a library with
unbuild
usingrollup
and generatingdist/*.cjs
anddist/*.mjs
files.As I didn't want to import directly from
lib/dist
, I created the followingpackage.json
:This
lib
depends on another lib,esm-only
.esm-only
is packaged as ESM but with.js
extension and I can't control how this library bundledMy App project uses
lib
. When I ran vitest on my App project, I got this error:The only thing I was able to make it work was to change
lib/package.json
to:And then change
src/lib.test.ts
to:But as you can see, I have
lib/dist/utils
, I want to be able to importlib/utils
instead.Another option is to change
lib/build.config.ts
to usemkdist
:And my
lib/package.json
to:Finally, this ONLY DOESN'T work on Vitest. On Vite I can normally run both in dev and production mode.
Related issues:
server.deps.inline
but it didn't workReproduction
I created this repository to reproduce the issue I was having in another project: https://github.com/varugasu/node-packages
esm-only
, thenpnpm build
lib
, thenpnpm build
app
, thenpnpm test
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: