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 restart nuxt: Cannot read properties of undefined (reading 'nuxt') #116

Open
oleksandr-dukhovnyy opened this issue Apr 10, 2023 · 5 comments

Comments

@oleksandr-dukhovnyy
Copy link

After the steps in the Setup section of the README, I get the following error.

Reproduction steps:

< mkdir folder
< cd folder
< nuxi init .
< npm i @nuxtjs/proxy
< npm i
(Setup steps from README)
< npm run dev

>ERROR  Cannot restart nuxt:  Cannot read properties of undefined (reading 'nuxt')                                                                  

 at proxyModule (node_modules\@nuxtjs\proxy\dist\index.js:38:21)
 at installModule (/C:/Users/user/Desktop/test-proxy/node_modules/@nuxt/kit/dist/index.mjs:452:21)
 at async initNuxt (/C:/Users/user/Desktop/test-proxy/node_modules/nuxt/dist/index.mjs:2475:7)
 at async load (/C:/Users/user/Desktop/test-proxy/node_modules/nuxi/dist/chunks/dev.mjs:6824:9)
 at async _applyPromised (/C:/Users/user/Desktop/test-proxy/node_modules/nuxi/dist/chunks/dev.mjs:6737:10)

Any idea how to fix it?

@oleksandr-dukhovnyy
Copy link
Author

Do I understand correctly that this module does not work with Nuxt 3+?
If so, then this seems to be the case. I'm trying to run it on Nuxt 3... I need to update the documentation and point out that this is a module for Nuxt 2.

@paul-asvb
Copy link

The proxy can also be configured through nitro docs in the nuxt.config.ts:

export default defineNuxtConfig({
  nitro: {
    devProxy: {
      "/proxy/test": "http://localhost:3001",
    },
  },
});

@robertpatrick
Copy link

@paul-asvb Even using the nitro config above, it still doesn't work.

export default defineNuxtConfig({
  devtools: { enabled: true },
  modules:  [
    '@nuxtjs/proxy',
    '@nuxt/devtools',
    '@nuxtjs/i18n',
    '@nuxtjs/eslint-module',
  ],
  ...
  nitro: {
    devProxy: { '/api': `http://localhost:${ process.env.SERVER_PORT || 8080 }` },
  },
});

Running nuxt dev still fails with the same error:

 % npm run dev

> dev
> nuxt dev

[11:01:13 AM] 


[11:01:13 AM] Nuxi 3.6.5
[11:01:13 AM] Nuxt 3.6.5 with Nitro 2.5.2
[11:01:15 AM] 
  > Local:    http://localhost:3000/ 
  > Network:  http://192.168.1.113:3000/
  > Network:  http://192.168.205.1:3000/
  > Network:  http://[fdbf:91fe:c74d:b58:105f:b1c7:9b46:617b]:3000/


[11:01:15 AM]  ERROR  Cannot start nuxt:  Cannot read properties of undefined (reading 'nuxt')

  at proxyModule (node_modules/@nuxtjs/proxy/dist/index.js:38:21)
  at installModule (node_modules/@nuxt/kit/dist/index.mjs:2409:101)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:3238:7)
  at async load (node_modules/nuxi/dist/chunks/dev.mjs:205:9)
  at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:249:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:49:20)

I am sure I must be doing something wrong but I can't figure out what it is...

@moisout
Copy link

moisout commented Aug 9, 2023

@paul-asvb Even using the nitro config above, it still doesn't work.

export default defineNuxtConfig({
  devtools: { enabled: true },
  modules:  [
    '@nuxtjs/proxy',
    '@nuxt/devtools',
    '@nuxtjs/i18n',
    '@nuxtjs/eslint-module',
  ],
  ...
  nitro: {
    devProxy: { '/api': `http://localhost:${ process.env.SERVER_PORT || 8080 }` },
  },
});

Running nuxt dev still fails with the same error:

 % npm run dev

> dev
> nuxt dev

[11:01:13 AM] 


[11:01:13 AM] Nuxi 3.6.5
[11:01:13 AM] Nuxt 3.6.5 with Nitro 2.5.2
[11:01:15 AM] 
  > Local:    http://localhost:3000/ 
  > Network:  http://192.168.1.113:3000/
  > Network:  http://192.168.205.1:3000/
  > Network:  http://[fdbf:91fe:c74d:b58:105f:b1c7:9b46:617b]:3000/


[11:01:15 AM]  ERROR  Cannot start nuxt:  Cannot read properties of undefined (reading 'nuxt')

  at proxyModule (node_modules/@nuxtjs/proxy/dist/index.js:38:21)
  at installModule (node_modules/@nuxt/kit/dist/index.mjs:2409:101)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:3238:7)
  at async load (node_modules/nuxi/dist/chunks/dev.mjs:205:9)
  at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:249:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:49:20)

I am sure I must be doing something wrong but I can't figure out what it is...

If you are using nitro devProxy you need to remove '@nuxtjs/proxy' from your modules.

@robertpatrick
Copy link

yeah, this module is irrelevant for Nuxt 3. Just use the nitro proxy and don't look back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants