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

Cannot find module 'vitest-environment-nuxt/module' #528

Closed
kirkbushell opened this issue Apr 17, 2023 · 17 comments
Closed

Cannot find module 'vitest-environment-nuxt/module' #528

kirkbushell opened this issue Apr 17, 2023 · 17 comments

Comments

@kirkbushell
Copy link

I've installed nuxt-vitest and seeing this error when trying to run tests, soon as I added the module to the nuxt config.

Unfortunately still new to the JS/TS ecosystem and struggling to debug, here is the full error:

FAIL app/components/registration/EmailForm.vue.spec.ts > Email form
Error: Cannot find module 'vitest-environment-nuxt/module'
Require stack:

  • /Users/----/Work/Mine/ho/index.js
    ❯ Function._resolve [as resolve] node_modules/jiti/dist/jiti.js:1:241025
    ❯ resolveModule node_modules/@nuxt/kit/dist/index.mjs:260:41
    ❯ normalizeModule node_modules/@nuxt/kit/dist/index.mjs:469:18
    ❯ Object.installModule node_modules/@nuxt/kit/dist/index.mjs:451:47
    ❯ setup node_modules/nuxt-vitest/dist/module.cjs:22:15
    ❯ normalizedModule node_modules/@nuxt/kit/dist/index.mjs:170:42
    ❯ installModule node_modules/@nuxt/kit/dist/index.mjs:452:95
    ❯ initNuxt node_modules/nuxt/dist/index.mjs:2616:7

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: {
"code": "MODULE_NOT_FOUND",
"requireStack": [
"/Users/----/Work/Mine/ho/index.js",
],
}

@danielroe
Copy link
Member

Would you provide a reproduction? 🙏

My guess is that possibly you haven't set up your vitest config as needed ...

@kirkbushell
Copy link
Author

Would you provide a reproduction? 🙏

My guess is that possibly you haven't set up your vitest config as needed ...

This is certainly possible, as I'm adding it to an existing project and I am struggling to find documentation to do that (rather than just creating a new app with vite.etc.)

@kirkbushell
Copy link
Author

kirkbushell commented Apr 18, 2023

Unfortunately I cannot seem to get a reproduction working, I can't even get tests to run... not sure what I've missed :/

Have copied my package json, the various config files, and the component I'm wanting to test, but nothing =\

Error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.

I do however have that installed, needed it locally, and don't see this error.

Copy link
Member

You can check out https://github.com/elk-zone/elk/blob/main/vitest.config.mjs to see how one project is configured.

Copy link
Member

Ahh, yes, that is a known issue with an open PR to resolve.

@kirkbushell
Copy link
Author

Okay, so no way to show a repro right now?

@kirkbushell
Copy link
Author

Any ideas on the error:

Error: Cannot find module 'vitest-environment-nuxt/module'

Currently I am unable to write any tests with a nuxt environment requirement.

@kirkbushell
Copy link
Author

kirkbushell commented Apr 18, 2023

Okay so more information, I've realised I'm seeing this with just running the nuxt server, as well.

If I remove the vitest plugin, it works as normal.

Also, coming back to this error:

`ERROR Cannot start nuxt: Cannot find module 'vitest-environment-nuxt/module' 12:01:09 AM
Require stack:

  • /Users/----/Work/Mine/ho/index.js

    Require stack:

    • index.js
      at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1021:15)
      at Function.resolve (node:internal/modules/cjs/helpers:114:19)
      at Function._resolve [as resolve] (node_modules/jiti/dist/jiti.js:1:241025)
      at resolveModule (node_modules/@nuxt/kit/dist/index.mjs:260:41) 12:01:09 AM
      at normalizeModule (node_modules/@nuxt/kit/dist/index.mjs:469:18)
      at Object.installModule (node_modules/@nuxt/kit/dist/index.mjs:451:47)
      at setup (node_modules/nuxt-vitest/dist/module.cjs:22:15)
      at normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:170:42)
      at async installModule (node_modules/@nuxt/kit/dist/index.mjs:452:95)
      at async initNuxt (node_modules/nuxt/dist/index.mjs:2616:7)`

There is no index.js in that folder - is it expecting one? Is that the problem?

@kirkbushell
Copy link
Author

Okay, apologies for the spam - I got passed it. I was actually missing the package for the vitest-evironment-nuxt (this doesn't appear to be mentioned anywhere). installed that, I'm now at the same error as above:

Error: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files.

This is now happening locally, so will take a look at the open PR.

@dsvgl
Copy link

dsvgl commented Apr 18, 2023

Why not simply creating a new nuxt 3 project on eg. Stackblitz via https://nuxt.new and adding the module and config over there.

@kirkbushell
Copy link
Author

Why not simply creating a new nuxt 3 project on eg. Stackblitz via https://nuxt.new and adding the module and config over there.

That's exactly what I did, and saw the errors above, which apparently are a known issue and should be resolved shortly - so I can't create a repro to showcase the problem lol

Copy link
Member

The latest version of the module includes the fix I mentioned - maybe you can try again now?

@kirkbushell
Copy link
Author

The latest version of the module includes the fix I mentioned - maybe you can try again now?

Already tested this morning, definitely fixed. Ty :)

@kirkbushell
Copy link
Author

Just one thing to add, I think the docs/instructions should point to the requirement of the environment package. I had to install it for it to work.

@DanielleConstell
Copy link

It seems this issue is back with Vitest version 0.31.0

@JasonLandbridge
Copy link

Thanks @kirkbushell , the fix is to install vitest-environment-nuxt

npm i -D vitest-environment-nuxt

@danielroe
Copy link
Member

This should be resolved in the latest version of Nuxt (v3.5.2) via nuxt/nuxt#21082.

@danielroe danielroe transferred this issue from danielroe/nuxt-vitest Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants