-
-
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
new URL throw error when environment is happy-dom
in 0.34.2
#3988
Comments
Start a new pull request in StackBlitz Codeflow. |
happy-dom
in 0.34.2
Happens with Specifically, I'm loading JSON fixtures from the file system in my |
This is expected behavior. Web transform mode does the same transformations that Vite does for browsers, and it transforms new URL('/package.json', self.location) To bypass this, I guess you can store You can find the change here: |
Would |
I switched to |
Importing |
I that ever breaks, I will add vite plugin to import json 😆. |
Got hit as well. Some conversion tests using csv fixtures (native import is limited in that case). Based on my usage I've just forced See https://vitest.dev/guide/environment.html#environments-for-specific-files |
@sheremet-va could you give an example about
In my case I have a function : const loadFixtureCsv = (file: string): ArrayBuffer => {
return readFileSync(new URL(`./__fixtures__/${file}`, import.meta.url), {
encoding: null,
});
}; But I don't see how I could store import.meta.url ? Thanks in advance |
I think just storing URL in a separate variable makes Vite bypass the transformation: const baseUrl = import.meta.url
const filePath = new URL(`./__fixtures__/${file}`, baseUrl) |
Indeed it works as well. Thanks for the tip. |
I think using any kind of node API like |
Can't you just use import md from './index.md?raw'
import.meta.glob('./*.md', { as: 'raw', eager: true }) |
Likely, but then eslint-plugin-import would start failing to resolve and would need extra config to work. Generally I try to avoid query parameters on imports. |
I'm encountering the same issue, the problem is I don't control the code that contains the |
Describe the bug
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-3da18m?file=setup.ts
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 16.20.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.6.10 - /usr/local/bin/pnpm npmPackages: vite: latest => 4.4.9
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: