Skip to content
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

Errors from running Vite nodejs tests #202

Closed
ydcjeff opened this issue Dec 17, 2021 · 13 comments
Closed

Errors from running Vite nodejs tests #202

ydcjeff opened this issue Dec 17, 2021 · 13 comments

Comments

@ydcjeff
Copy link
Contributor

ydcjeff commented Dec 17, 2021

I tried to migrate Vite nodejs tests to Vitest. Half of them passed and half failed.

I don't know how to debug this, so make a report here.

Reproduction: https://github.com/ydcjeff/vite/tree/test/vitest

Reproduction steps:

  • pnpm i
  • cd packages/vite && pnpm run dev
  • pnpm run test-serve (2nd terminal)

Error trace:

Screen Shot 2021-12-17 at 22 38 35

@antfu antfu added the bug label Dec 20, 2021
@ydcjeff
Copy link
Contributor Author

ydcjeff commented Dec 24, 2021

The last error from the screenshot can be fixed by adding exports field in totalist package.json.

The other errors still remained unfixed.

@antfu
Copy link
Member

antfu commented Dec 24, 2021

Try add define: { "process.env.NODE": "process.env.NODE" } in vitest.config

And add totalist to test: { deps: { inline: ['totalist'] }}}

@ydcjeff
Copy link
Contributor Author

ydcjeff commented Dec 26, 2021

unfortunately, it didn't work.

@atk
Copy link
Contributor

atk commented Dec 26, 2021

Shouldn't it be define: { "process.env.NODE": process.env.NODE }?

@vinothvk
Copy link

I am also seeing this 'Directory import xyz is not supported resolving ES Modules imported from' error
tried using deps.inline and it didn't help

@sheremet-va
Copy link
Member

So, I found that we always replace NODE_ENV because of this: https://github.com/vitejs/vite/blob/3480f27d4db7f7ebd27164d9185e7b387762274e/packages/vite/src/node/plugins/clientInjections.ts#L52

@antfu do you have any ideas how we can bypass this? I wanted to redefine define config in Vitest plugin - instead of replacing it statically, I wanted to put them on global, so people can reassign them in tests. Right now this is impossible to do with NODE_ENV

@antfu
Copy link
Member

antfu commented Feb 15, 2022

We could just remove the vite:client-inject plugin in configResolve to see if it fixes the issue

@sheremet-va
Copy link
Member

sheremet-va commented Feb 15, 2022

We could just remove the vite:client-inject plugin in configResolve to see if it fixes the issue

It failes, because /@vite/env depends on it:

ReferenceError: __DEFINES__ is not defined
    at C:/Users/Vladimir/Documents/git/vitest/test/core/@vite/env:16:17

@sheremet-va
Copy link
Member

I'm not sure if this else if is really needed? Doesn't NODE_ENV get replaced by define-plugin?

@patak-dev
Copy link
Member

patak-dev commented Feb 15, 2022

Maybe we could split vite:client-inject in Vite core in two plugins so we only get __DEFINES__ for Vitest

Or actually, we could remove vite:client-inject and add a copy of it in Vitest that only injects __DEFINES__?

@sheremet-va
Copy link
Member

Maybe we could split vite:client-inject in Vite core in two plugins so we only get __DEFINES__ for Vitest

Or actually, we could remove vite:client-inject and add a copy of it in Vitest that only injects __DEFINES__?

I like your first idea more :P

@sheremet-va
Copy link
Member

Is this still a problem?

@ydcjeff
Copy link
Contributor Author

ydcjeff commented May 6, 2022

This is no longer a problem since

@ydcjeff ydcjeff closed this as completed May 6, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants