nuxt: Cannot start application, Nuxt loading node modules from incorrect directory

Environment


  • Operating System: Darwin
  • Node Version: v17.9.0
  • Nuxt Version: 3.0.0-rc.10
  • Nitro Version: 0.5.3
  • Package Manager: npm@8.5.5
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

npx nuxi init nuxt-app npm i npm run dev

Describe the bug

Immediately hit with “Cannot find package ‘@vue/server-renderer’ imported from /Users/marco/node_modules/vue/server-renderer/index.mjs”

I’ve tried installing multiple times but no luck so far.

Additional context

Screen Shot 2022-09-15 at 2 03 51 PM

Logs

✔ Nitro built in 481 ms
ℹ Vite client warmed up in 1322ms
[nuxt] [request error] [unhandled] [500] Cannot find package '@vue/server-renderer' imported from /Users/marco/node_modules/vue/server-renderer/index.mjs
  at new NodeError (node:internal/errors:372:5)
  at packageResolve (node:internal/modules/esm/resolve:908:9)
  at moduleResolve (node:internal/modules/esm/resolve:957:20)
  at defaultResolve (node:internal/modules/esm/resolve:1173:11)
  at ESMLoader.resolve (node:internal/modules/esm/loader:604:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
  at link (node:internal/modules/esm/module_job:78:36)
^C

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (15 by maintainers)

Most upvoted comments

As an update, we had a quick call with @marcodarko. Removing or renaming stale node_modules from home directory solves the issue. It is an environment-specific issue. Trying to find a solution for it but as quick workaround, simply remove the directory.

Thanks once again @marcodarko for reproduction. Moving this issue to https://github.com/nuxt/nuxt.js/issues/14952. It is related to the vite-node package that is enabled.

Could that issue be related to https://github.com/nuxt/nuxt.js/issues/14802 too?

Happy to meet anytime

@marcodarko @angelhdzmultimedia Any hope we can set a session so you can share your desktop? (Still trying to reproduce locally but might help to speed up)

I have some theories about the issue but rc.10 works fine on my machine so still need reproduction. It might be specific to your machine.

Can you please share output of this config:

export default defineNuxtConfig({
  hooks: {
    'ready'(nuxt) {
      console.log('Workspace dir:', nuxt.options.workspaceDir)
      console.log('Modules dir:', nuxt.options.modulesDir)
    }
  }
})

If there is /Users/marco/node_modules in there and specially you have /Users/marco/node_modules/vue (v2) it can cause the issue. You shouldn’t have node_modules inside the home directory. If possible try to remove it.

“It works on my machine”

I do but I have tried creating a new project in multiple locations and all the same result. I’ve tried deleting them and reinstalling but same thing happens. These are the logs: https://github.com/nuxt/nuxt.js/issues/14928

Tried to uninstall my global vue module and rerun to see if it was interfering but no luck so then I re-installed it and now get a new error (probably because it loaded the wrong version of vue from /User/marco not the project dir):

[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[nuxt] [request error] [unhandled] [500] Cannot read property 'modules' of undefined
  at _sfc_main.setup (./node_modules/nuxt/dist/app/components/nuxt-root.vue:67:16)  
  at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7109:29)  
  at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7064:11)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:172:17)  
  at renderToString (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:450:26)  
  at Object.renderToString$1 [as renderToString] (./.nuxt/dev/index.mjs:472:24)  
  at Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:173:40)  
  at processTicksAndRejections (node:internal/process/task_queues:94:5)  
  at async ./.nuxt/dev/index.mjs:527:21
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[nuxt] [request error] [unhandled] [500] Cannot read property 'modules' of undefined
  at _sfc_main.setup (./node_modules/nuxt/dist/app/components/nuxt-root.vue:67:16)  
  at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7109:29)  
  at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7064:11)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:172:17)  
  at renderToString (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:450:26)  
  at Object.renderToString$1 [as renderToString] (./.nuxt/dev/index.mjs:472:24)  
  at Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:173:40)  
  at processTicksAndRejections (node:internal/process/task_queues:94:5)  
  at async ./.nuxt/dev/index.mjs:527:21
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[nuxt] [request error] [unhandled] [500] Cannot read property 'modules' of undefined
  at _sfc_main.setup (./node_modules/nuxt/dist/app/components/nuxt-root.vue:67:16)  
  at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7109:29)  
  at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7064:11)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:172:17)  
  at renderToString (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:450:26)  
  at Object.renderToString$1 [as renderToString] (./.nuxt/dev/index.mjs:472:24)  
  at Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:173:40)  
  at processTicksAndRejections (node:internal/process/task_queues:94:5)  
  at async ./.nuxt/dev/index.mjs:527:21
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[nuxt] [request error] [unhandled] [500] Cannot read property 'modules' of undefined
  at _sfc_main.setup (./node_modules/nuxt/dist/app/components/nuxt-root.vue:67:16)  
  at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7109:29)  
  at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7064:11)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:172:17)  
  at renderToString (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:450:26)  
  at Object.renderToString$1 [as renderToString] (./.nuxt/dev/index.mjs:472:24)  
  at Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:173:40)  
  at processTicksAndRejections (node:internal/process/task_queues:94:5)  
  at async ./.nuxt/dev/index.mjs:527:21
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>
[Vue warn]: inject() can only be used inside setup() or functional components.
[Vue warn]: Server rendering context not provided. Make sure to only call useSSRContext() conditionally in the server build.
[Vue warn]: Unhandled error during execution of setup function 
  at <NuxtRoot>