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

Since vitest 0.30 : SyntaxError: Cannot use import statement outside a module when running tests #154

Closed
acmichaud opened this issue Apr 28, 2023 · 5 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@acmichaud
Copy link

Describe the bug
When I run ALL the tests using the vscode extension, I get this error
image

/.../vitest.config.js:2

import { defineConfig } from 'vite'

^^^^^^

SyntaxError: Cannot use import statement outside a module

And the test just runs until I press stop.
The thing is that the debug play button works fine ...
image

To Reproduce
Here is my configuration :

vitest.config.js

import { defineConfig } from 'vite'
// other imports

export default defineConfig({
//.......
})

Environment

  • OS: Windows
  • VSCode version: 1.77.3
  • Vitest version: 0.30.1
  • Vitest plugin version: v0.2.39
@acmichaud acmichaud added the p3-minor-bug An edge case that only affects very specific usage (priority) label Apr 28, 2023
@coderwei99
Copy link

I encountered this problem in the my monorepo project, I set type=module in package. json to solve my problem. I don't know if that's gonna solve your problem

{
  "type": "module",   //here
  "scripts": {
       // your code
  }
}

@acmichaud
Copy link
Author

Hi there! This solved the error thx!...

But now I get a new one :(

Test result not found. 
If you set `vitest.commandLine` please check: 
    Did you set `vitest.commandLine` to `run` mode? (This extension requires `watch` mode to get the results from Vitest api)
    Does it have the ability to append extra arguments? (For example it should be `yarn test --` rather than `yarn test`)
Are there tests with the same name?
Can you run vitest successfully on this file? Does it need custom option to run?

Again, the debug tests works fine and also the command line vitest run are working.

@coderwei99
Copy link

#47
here

@kcaswick
Copy link

I encountered this error as well. Seems like if npx vitest can detect that it is an ESM without the type in package.json, so should this extension.

@acmichaud
Copy link
Author

Here is the link to the solution : #47 (comment)
It worked for me.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants