question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RC 9] [RC 10] `Cannot read properties of undefined (reading 'modules')` when `vue` is installed in parent dir

See original GitHub issue

Related issues

Reproduction

Minimal reproduction: https://stackblitz.com/edit/github-2yn1ze?file=app%2Fpackage.json,app%2Fnuxt.config.ts

Describe the bug

How it happens: If vue dependency is installed outside of project directory in an adjutant directory (usually home directory with node_modules), vite-node that is enabled by default for RC.9+ makes issues. (issue is with nuxt custom external options)

Additional context

Workaround 1

Try switching to the edge channel. It should have been solved with #7612.

Workaround 2

Check your home directory. If there is any node_modules dir, remove it or rename it. It is probably created wrongly in the past.

Workaround 3

It might be also because of a monorepo setup that has ../node_modules/vue dependency. In this case, switch to the legacy vite bundler:

export default defineNuxtConfig({
  vite: {
    devBundler: 'legacy',
  },
});

Remarks

The root cause of this issue is having multiple instances of vue in externals. In the future similar issue might happen with different causes as vue does not support multiple version instances.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
l4dybirdcommented, Dec 10, 2022

@theolavaux It can be solved by modifying the package.json of each package as follows.

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@vue/server-renderer": "3.2.45",
    "@vue/runtime-core": "3.2.45",
    "nuxt": "3.0.0",
    "vue": "3.2.45",
    "vue-bundle-renderer": "1.0.0"
  }
}

sample https://github.com/l4dybird/nuxt3-monorepo

1reaction
andreas83commented, Sep 17, 2022

i had this issue even with 3.0.0-rc.11-27722816.abd0feb, node_modules removed from project and parent dir as well adding legacy devBunder to nuxt.config.ts.

At the end, removing the yarn.lock file fixed the issue for me.


Nuxt 3.0.0-rc.11-27722816.abd0feb with Nitro 0.5.4-27719614.c3af02d                                                                                                      09:58:22
                        
[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 properties of undefined (reading 'modules')
  at _sfc_main.setup (./node_modules/nuxt/dist/app/components/nuxt-root.vue:67:16)  
  at callWithErrorHandling (./node_modules/vue/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/vue/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7109:29)  
  at setupComponent (./node_modules/vue/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:96:5)  
  at async ./.nuxt/dev/index.mjs:527:21


  • Operating System: Linux
  • Node Version: v16.13.1
  • Nuxt Version: 3.0.0-rc.11-27722816.abd0feb
  • Nitro Version: 0.5.4-27719614.c3af02d
  • Package Manager: yarn@1.21.1
  • Builder: vite
  • User Config: buildModules, publicRuntimeConfig
  • Runtime Modules: -
  • Build Modules: nuxt-windicss@2.5.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'vue')
I am new to Vue js and faced with the following problem: When trying to launch a project, an error occurs: Cannot read...
Read more >
cannot read properties of undefined (reading 'create') node js
I am new to Vue js and faced with the following problem: When trying to launch a project, an error occurs: Cannot read...
Read more >
How To Manage State in a Vue.js Application with Vuex
Getters are methods that can modify or combine data to create a new state property. These getters are read-only and do not mutate...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
{10,12}: sysprof-modules crashes system when playing music" status:RESOLVED resolution:OBSOLETE severity:normal · Bug:226025 - "app-admin/guidance (new ...
Read more >
Working with Rules - ESLint - Pluggable JavaScript Linter
In a custom rule or plugin, you can omit docs or include any properties that you need in it. fixable (string) is either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found