Comments (3)
I've seen a similar issue recently and your case is somewhat similar where wagmi
is somehow inlined (i.e. processed vite/vitest transform).
I thought there might be some packaging issue of wagmi, but they are all green on publint, so there might be a problem with Vitest's externalization heuristics.
For the time being, I think it should be safe to explicitly set server.deps.external
, so that wagmi
always ends up with import("wagmi")
, meaning there is only a single copy managed by NodeJs.
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "jsdom",
server: {
deps: {
external: ["wagmi"]
}
}
},
});
I'll need to look into further to see where the issue lies.
from vitest.
Thank you for help, I can confirm that this workaround/fix works!
from vitest.
Vitest's externalization heuristic is based on isValidNodeImport
and this might be the one having an issue.
vitest/packages/vite-node/src/externalize.ts
Lines 64 to 72 in 6eda473
As mentioned in the comment, isValidNodeImport
seems to be copied from mlly
, but the original one actually has a flipped condition where it checks pkg.type === "module"
before .../esm/...js
:
https://github.com/unjs/mlly/blob/c5bcca0cda175921344fd6de1bc0c499e73e5dac/src/syntax.ts#L82-L90
const package_ = await readPackageJSON(resolvedPath).catch(() => {});
// @ts-ignore
if (package_?.type === "module") {
return true;
}
if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(resolvedPath)) {
return false;
}
wagmi
is resolved to ./dist/esm/exports/index.js
, so the regex check hits first and isValidNodeImport
is returning false
on Vitest.
I wonder if Vitest introduced this flipped version on purpose or it may be a simple oversight. The PR #4368 is quite big, so I haven't gone through all the context.
from vitest.
Related Issues (20)
- Vitest does not discover tests in workspaces
- Ability to customize the "assetPrefix" for HTML report. HOT 5
- Error: Vitest failed to access its internal state.
- NestJS E2E tests failing when using vitest (when using sequelize query) HOT 7
- `expect.getState().testPath` only works when called inside of test function HOT 1
- Vitest TypeError. VItest not see global.d.ts file HOT 1
- Extend existing `list` command to output only a list of file names HOT 3
- stubs to contain events and props HOT 1
- Tasks (tests, suites, hooks) that are too fast show a duration of 0ms in Task results HOT 1
- TSC error with Vitest 2.0.5: missing declarations for "chai"
- Incorrect Branch Coverage with coverage-v8 in Browser Mode and export Declaration HOT 4
- Support for LCOV Reporter in Vitest UI to Improve Coverage Report Organization
- Plugin order not respected the same as dev or build. HOT 1
- Test with `expect(promise).resolves` with promise that never resolves and without `await` hangs HOT 1
- Incorrect test results on *first* run after installing node_modules HOT 4
- support passing through arguments HOT 4
- in vitest browser runner plugin with transformIndexHtml to inject importmap script manually does not work. HOT 5
- Secondary `resolveId` calls on virtual modules HOT 1
- Violent crash on stack-trace parsing HOT 2
- Node.js subpath import not working HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.