proxy-module icon indicating copy to clipboard operation
proxy-module copied to clipboard

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

Open oleksandr-dukhovnyy opened this issue 2 years ago • 5 comments

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 avatar Apr 10 '23 14:04 oleksandr-dukhovnyy

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.

oleksandr-dukhovnyy avatar Apr 10 '23 14:04 oleksandr-dukhovnyy

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

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

paul-asvb avatar Jul 03 '23 11:07 paul-asvb

@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...

robertpatrick avatar Aug 03 '23 16:08 robertpatrick

@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.

moisout avatar Aug 09 '23 19:08 moisout

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

robertpatrick avatar Aug 09 '23 19:08 robertpatrick