-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cannot require a module when using typescript #846
Comments
Vitest is ESM first. requiring non js files is not supported. Vite resolver is asynchronous, so we can not intercept it in any way. In fact, when you call require, it just calls Native Node require, that's why you are getting an error. Please, use import in your source code. |
@sheremet-va Ive added import() but i get both a v8 error and it says "no test suite found in file" for every test suite. Even though there's clearly a test suite there. Are you able to help? its the same reproduction steps as before Here is the output
Config // vite.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
watch: false,
setupFiles: ['./src/__test__/setup.ts'],
},
}); |
I also encountered this problem. If use format import { defineConfig } from 'vitest/config'
export default defineConfig({
esbuild: {
target: 'node14',
format: 'cjs'
},
}) it will cannot this is working in jest, because the hook Not use format import { defineConfig } from 'vitest/config'
export default defineConfig({
esbuild: {
target: 'node14',
},
}) esbuild will not transform source There is a contradiction between the two behaviors. A possible solution might be to convert |
As I said above, hook // hook.ts
import { EsbuildPhoenix } from '@xn-sakina/phoenix'
// Implemented esbuild hook require() to support import `.ts` files
new EsbuildPhoenix({
target: 'es2019'
}) vitest config: // vitest.config.ts
import { defineConfig } from https://github.com/vitest-dev/vitest
export default defineConfig({
test: {
setupFiles: ['./hook']
},
esbuild: {
target: 'node14',
format: 'cjs'
},
}) But I didn't run a speed benchmark and I'm not sure faster than |
Co-authored-by: webfansplz <>
Not sure what else we can help with.
|
Hi! I resolved this issue by adding In component:
in
|
Describe the bug
Im trying to migrate next-page-tester from jest to vitest. When running the test runner I get the error:
However running the same test in Jest passes fine.
The above looks like it needs the file extension to the module, so when i manually add that I get a different error.
Reproduction
npx jest src/__tests__/404/404.test.tsx
(works)npx vitest src/__tests__/404/404.test.tsx
(fails)System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: