nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.76k stars 483 forks source link

[NEXT] Cannot start nuxt: Cannot find module 'node_modules/vue-i18n/dist/vue-i18n.mjs' #1568

Closed cdefy closed 2 years ago

cdefy commented 2 years ago

Hi,

I'm currently using vue-i18n as a plugin in a Nuxt 3 project but I would like to switch to @nuxtjs/i18n as soon as possible. I tried to installed the alpha version but as soon as I declare the module in nuxt.config.js, I've got an error when I do npm run dev.

Cannot find module '.../node_modules/vue-i18n/dist/vue-i18n.mjs'

  at createEsmNotFoundErr (node:internal/modules/cjs/loader:983:15)
  at finalizeEsmResolution (node:internal/modules/cjs/loader:976:15)
  at resolveExports (node:internal/modules/cjs/loader:493:14)
  at Function.Module._findPath (node:internal/modules/cjs/loader:533:31)
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
  at Function.resolve (node:internal/modules/cjs/helpers:108:19)
  at Function._resolve [as resolve] (node_modules/jiti/dist/jiti.js:1:243257)
  at resolveModule (node_modules/@nuxt/kit/dist/index.mjs:261:29)
  at setupAlias (node_modules/@nuxtjs/i18n/dist/module.mjs:25:36)
  at setup (node_modules/@nuxtjs/i18n/dist/module.mjs:541:11)
  at async Object.normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:642:5)
  at async installModule (node_modules/nuxt/node_modules/@nuxt/kit/dist/index.mjs:456:3)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:1606:7)
  at async load (node_modules/nuxi/dist/chunks/dev.mjs:6778:9)
  at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:6828:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:50:20)

Indeed there is no such file in node_modules/vue-i18n/dist/ Any help will be appreciated!

kazupon commented 2 years ago

Thank you for reporting! Could you give us to minimum reproduction please? 🙏

ahoiroman commented 2 years ago

Same here. Basically followed https://v8.i18n.nuxtjs.org/getting-started/setup and https://v8.i18n.nuxtjs.org/getting-started/basic-usage .

- Operating System: `Darwin`
- Node Version:     `v18.9.0`
- Nuxt Version:     `3.0.0-rc.12`
- Nitro Version:    `0.6.0`
- Package Manager:  `npm@8.19.1`
- Builder:          `vite`
- User Config:      `experimental`, `build`, `modules`, `publicRuntimeConfig`, `privateRuntimeConfig`, `globalName`, `app`, `i18n`, `http`, `proxy`, `auth`, `tailwindcss`, `googleFonts`, `content`
- Runtime Modules:  `@nuxtjs-alt/auth@2.0.16`, `@nuxtjs-alt/http@1.3.18`, `@nuxtjs-alt/proxy@1.3.5`, `@nuxt/content@2.2.0`, `@nuxtjs/tailwindcss@5.3.5`, `@nuxtjs/google-fonts@3.0.0-0`, `@pinia/nuxt@0.4.3`, `@nuxtjs/i18n@8.0.0-alpha.3`
- Build Modules:    `-`
ahoiroman commented 2 years ago

Upgraded to beta.1 - issue remains the same:

- Operating System: `Darwin`
- Node Version:     `v18.9.0`
- Nuxt Version:     `3.0.0-rc.12`
- Nitro Version:    `0.6.0`
- Package Manager:  `npm@8.19.1`
- Builder:          `vite`
- User Config:      `experimental`, `build`, `modules`, `publicRuntimeConfig`, `privateRuntimeConfig`, `globalName`, `app`, `i18n`, `http`, `proxy`, `auth`, `tailwindcss`, `googleFonts`, `content`
- Runtime Modules:  `@nuxtjs-alt/auth@2.0.16`, `@nuxtjs-alt/http@1.3.18`, `@nuxtjs-alt/proxy@1.3.5`, `@nuxt/content@2.2.0`, `@nuxtjs/tailwindcss@6.0.1`, `@nuxtjs/google-fonts@3.0.0-0`, `@pinia/nuxt@0.4.3`, `@nuxtjs/i18n@8.0.0-beta.1`
- Build Modules:    `-`
ahoiroman commented 2 years ago

I was able to solve the issue by not only removing the old package @intlify/nuxt3@0.2.4 from nuxt.config.js but also from package.json and running npm update.

LePtiDev commented 2 years ago

I have the same issue on the 8.0.0-beta.1

The install is working but when i start the server he won't start on this error:

Cannot start nuxt: Cannot find module '/Users/quentinguerrier/Desktop/seiz-io/oms/node_modules/vue-i18n/dist/vue-i18n.mjs'

This is in my package.json :

"@capacitor/browser": "^4.0.1", "@commitlint/cli": "^17.0.3", "@commitlint/config-conventional": "^17.0.3", "@commitlint/cz-commitlint": "^17.0.3", "@headlessui/vue": "^1.6.7", "@heroicons/vue": "^2.0.11", "@intlify/nuxt3": "^0.2.4", "@meforma/vue-toaster": "^1.3.0", "@nuxtjs/eslint-config-typescript": "^11.0.0", "@nuxtjs/google-fonts": "3.0.0-0", "@nuxtjs/strapi": "^1.5.1", "@nuxtjs/tailwindcss": "5.3.2", "commitizen": "^4.2.5", "cordova-res": "0.15.4", "daisyui": "^2.31.0", "eslint": "^8.23.1", "eslint-config-prettier": "^8.5.0", "eslint-plugin-prettier": "^4.2.1", "husky": "^8.0.1", "lodash": "^4.17.21", "moment": "^2.29.4", "nuxt": "3.0.0-rc.11", "prettier": "^2.7.1", "sass": "^1.54.5", "tailwindcss": "3.1.0", "v-calendar": "3.0.0-alpha.8", "vee-validate": "^4.6.9", "vue3-smooth-scroll": "^0.8.1", "yup": "^0.32.11"

smartfox87 commented 2 years ago

I have the same issue on the 8.0.0-beta.1

smartfox87 commented 2 years ago

I solved this problem npm i vue-i18n@9.3.0-beta.6

cdefy commented 2 years ago

Hi @kazupon

I started a project from scratch to see if I had the same Cannot find module error. But I have another one. ^^

I just did npx nuxi init nuxt-app then npm i ; run the app OK. Stopped and did npm install @nuxtjs/i18n@next --save.

But with a basic nuxt.config.ts (just declaring the module, or declaring the module and setting basic options like below), I have a Cannot read properties of undefined (reading 'path') error when trying to do npm run dev

// nuxt.config.ts
export default defineNuxtConfig({  
  modules: ['@nuxtjs/i18n'], 
  i18n: {
    vueI18n: {
      legacy: false, 
      locale: 'en', 
      messages: { 
        en: { 
          welcome: 'Welcome' 
        },
        fr: { 
          welcome: 'Bienvenue'
        }
      }
    }
  }
})
// Error in terminal when running npm run dev
[nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading 'path')
  at Module.detectBrowserLanguage (virtual:nuxt:./.nuxt/i18n.internal.mjs:190:70)  
  at Module.detectLocale (virtual:nuxt:./.nuxt/i18n.utils.mjs:130:87)  
  at ./node_modules/@nuxtjs/i18n/dist/runtime/plugin.mjs:53:45  
  at processTicksAndRejections (node:internal/process/task_queues:96:5)  
  at async Object.callAsync (./node_modules/unctx/dist/index.mjs:53:16)  
  at async applyPlugin (./node_modules/nuxt/dist/app/nuxt.mjs:94:23)  
  at async Module.applyPlugins (./node_modules/nuxt/dist/app/nuxt.mjs:104:5)  
  at async createNuxtAppServer (./node_modules/nuxt/dist/app/entry.mjs:30:7)  
  at async default (./node_modules/@nuxt/vite-builder/dist/runtime/vite-node.mjs:27:18)  
  at async Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:172:19)
[nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading 'path')
  at Module.detectBrowserLanguage (virtual:nuxt:./.nuxt/i18n.internal.mjs:190:70)  
  at Module.detectLocale (virtual:nuxt:./.nuxt/i18n.utils.mjs:130:87)  
  at ./node_modules/@nuxtjs/i18n/dist/runtime/plugin.mjs:53:45  
  at processTicksAndRejections (node:internal/process/task_queues:96:5)  
  at async Object.callAsync (./node_modules/unctx/dist/index.mjs:53:16)  
  at async applyPlugin (./node_modules/nuxt/dist/app/nuxt.mjs:94:23)  
  at async Module.applyPlugins (./node_modules/nuxt/dist/app/nuxt.mjs:104:5)  
  at async createNuxtAppServer (./node_modules/nuxt/dist/app/entry.mjs:30:7)  
  at async default (./node_modules/@nuxt/vite-builder/dist/runtime/vite-node.mjs:27:18)  
  at async Object.renderToString (./node_modules/vue-bundle-renderer/dist/runtime.mjs:172:19)

To be sure I removed .nuxt, node_modules and package-lock.json and did an npm i again but same. The package.json has only nuxt and @nuxtjs/i18n and my Node version is 16.17.0

  {
    "private": true,
    "scripts": {
      "build": "nuxt build",
      "dev": "nuxt dev",
      "generate": "nuxt generate",
      "preview": "nuxt preview",
      "postinstall": "nuxt prepare"
    },
    "devDependencies": {
      "nuxt": "3.0.0-rc.12"
    },
    "dependencies": {
      "@nuxtjs/i18n": "^8.0.0-beta.1"
    }
}

Thanks @ahoiroman for sharing but in my case I don't have @intlify/nuxt3@0.2.4 ; not in my current project nor in this test one.

@smartfox87 It's a workaround as I reckon we shouldn't need to install vue-i18n?

kazupon commented 2 years ago

@cdefy Hi! Sorry, late my response. Thank you for your repotting

I think your issue is same in here That issue has already fixed. Please check it in edge-version!

kazupon commented 2 years ago

This issue may have been caused by migration from @intlify/nuxt3. I’ve tried to create a nuxt3 project as clean and installing @nuxtjs/i18n, this issue does not occur.

So I will close it. Thanks!

cdefy commented 2 years ago

@kazupon No worries for the delay and thank you but you closed this thread based on the second error I mentioned. I tried again on a new project and yes the Cannot read properties of undefined (reading 'path') error is gone but not the Cannot find module '.../node_modules/vue-i18n/dist/vue-i18n.mjs' I declared for this thread when trying to install @nuxti18n in a project already working.

I can't share my project but maybe @ahoiroman , @LePtiDev or @smartfox87 have an example they can share please?

Otherwise I'll try to reproduce on a fresh project when I have some time, but I just saw that in a new project the vue-i18n.msj is there but not on my current project even if I'm doing the same command and config!

JPustkuchen commented 1 year ago

@kazupon I' still running into this issue and the path /node_modules/dist/vue-i18n.mjs definitely isn't existing!

Tried all things mentioned above, but nothing helped. Running npm run dev isn't working with that error.

[nitro] [dev] [unhandledRejection] [[vite-node] [ERR_MODULE_NOT_FOUND] /node_modules/dist/vue-i18n.mjs 12:34:32 at /node_modules/dist/vue-i18n.mjs ] { statusCode: 500, fatal: false, unhandled: false, statusMessage: 'Vite Error' }

Here's my package.json:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@nuxt/content": "^2.2.2",
    "@nuxt/image-edge": "^1.0.0-27840416.dc1ed65",
    "@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge",
    "@sidebase/nuxt-auth": "^0.3.0",
    "nuxt": "^3.0.0",
    "nuxt-purgecss": "^2.0.0",
    "sass": "^1.56.2"
  },
  "dependencies": {
    "@mdi/font": "^7.1.96",
    "@nuxt/test-utils": "^3.0.0",
    "@nuxtjs/robots": "^3.0.0",
    "@pinia/nuxt": "^0.4.6",
    "pinia": "^2.0.28",
    "vuetify": "^3.0.4"
  },
  "overrides": {
    "vue": "^3"
  }
}

and here's my nuxt.config.ts:

export default defineNuxtConfig({
   modules: [
     '@nuxtjs/i18n',
     '@nuxt/image-edge',
     '@nuxtjs/robots',
     '@nuxt/content',
     'nuxt-purgecss',
     '@pinia/nuxt', // https://nuxt.com/modules/pinia
     '@sidebase/nuxt-auth', // https://nuxt.com/modules/nuxt-auth
   ],
 [...]

The project was created from scratch just yesterday. Could we reopen this? Any ideas?

If I manually add npm i vue-i18n

it's exactly the same issue (with the configuration above). Did the paths change perhaps? /node_modules/dist/vue-i18n.mjs looks strange in general here?

I'm confused...

kazupon commented 1 year ago

If is it possible, Could you give us your project with github repo or stackbliz? else you could not it, We would give us your minumum repo. 🙏

JPustkuchen commented 1 year ago

@kazupon sadly it's not public. I'll try to reproduce this in a minimum public repo install. Perhaps someone else here already has a public repo with the same issue?

kazupon commented 1 year ago

I tried to fix this issue. you can use the edge-version 8.0.0-beta.7-27847653.226e24b

pimboden commented 1 year ago

I tried to fix this issue. you can use the edge-version 8.0.0-beta.7-27847653.226e24b

In installed that... now I get Cannot start nuxt: Cannot resolve vue-i18n on pnpm! please install it on 'node_modules'

kazupon commented 1 year ago

@pimboden Could you give us your node_modules tree please? 🙏

Rodrig0v commented 1 year ago

I tried to fix this issue. you can use the edge-version 8.0.0-beta.7-27847653.226e24b

In installed that... now I get Cannot start nuxt: Cannot resolve vue-i18n on pnpm! please install it on 'node_modules'

I fixed this by adding a .npmrc file with shamefully-hoist=true in the root folder

kazupon commented 1 year ago

I fixed this by adding a .npmrc file with shamefully-hoist=true in the root folder

Yes! If you are using pnpm, we need shamefully-hoist option! That is mentioned by nuxt official docs https://nuxt.com/docs/getting-started/installation

JPustkuchen commented 1 year ago

FYI as written above, we were NOT using pnpm, just npm. I'll have a look at the fix asap!

productdevbook commented 1 year ago

@kazupon

shamefully-hoist=true
strict-peer-dependencies=false

turbo monorepo same problem,

    "@intlify/vue-i18n-bridge": "^0.8.0",
    "@intlify/vue-router-bridge": "^0.8.0",
        "vue-i18n-routing": "^0.10.2",

I had to download these, only your library is the problem

Cyclodex commented 1 year ago

I just run into the same issue, with Could not read from file: C:\...\nuxt-base\node_modules\dist\vue-i18n.mjs

What did I do

I just installed the latest vuetify, to try it out... Now my setup is not working anymore.

Analyzing

I checked the version with npm ls vue-i18n, with vuetify and without: With vuetify@3.1.1, it has a dependency of vue-i18n@9.2.2 - is this the problem here ? (while there is vue-i18n@9.3.0 mentioned from @nuxtjs/i18n

image

Without vuetify, nuxt generates the .nuxt/types including the following correct path: image

With vuetify, it somehow misses the package folder name in the path: image

How can this happen? Is there a way we can trick out the package dependency?

UPDATE: Oh I just see that there is also a difference with the vue-i18n@9.3.0-beta version

Cyclodex commented 1 year ago

I think I solved the issue, with defining the override within package.json for now:

"overrides": {
  "vue-i18n": "^9.3.0-beta.14"
}
CMQNordic commented 1 year ago

I have the same issue following installation in this official guide: https://v8.i18n.nuxtjs.org/getting-started/setup

I have a working nuxt 3 project based on "nuxt": "^3.0.0-rc.14", After enabling in modules: [ '@nuxtjs/i18n' ],

I get this error when running :npm run dev

[ERROR] Could not read from file: C:\Users\marti\OneDrive\Jobb\Development\WebDev\starters\vuetify-3-nuxt-3-full-project-starter\node_modules\dist\vue-i18n.mjs

I see this issue have bee around for a while.. Is this fixed? Is the official guide hpw to set it up with nuxt 3 up to date? https://v8.i18n.nuxtjs.org/getting-started/setup

Cyclodex commented 1 year ago

@CMQNordic What is your output of running npm ls vue-i18n ? Did you try my workaround above ?

dawadam commented 1 year ago

Hi, I have the same problem on a fresh nuxt3 project :

500 [vite-node] [ERR_MODULE_NOT_FOUND] /node_modules/dist/vue-i18n.mjs

@Cyclodex my npm ls vue-i18n is :

├─┬ @nuxtjs/i18n@8.0.0-beta.7
│ ├─┬ @intlify/unplugin-vue-i18n@0.8.1
│ │ └── vue-i18n@9.2.2 deduped
│ ├─┬ vue-i18n-routing@0.10.2
│ │ ├─┬ @intlify/vue-i18n-bridge@0.8.0
│ │ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped
│ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped
│ └── vue-i18n@9.3.0-beta.14-77e850b
└─┬ vuetify@3.1.0
  └── vue-i18n@9.2.2

==========

EDIT : Thanks @Cyclodex, using "^9.3.0-beta.14" work great. Now my npm ls vue-i18n is :

├─┬ @nuxtjs/i18n@8.0.0-beta.7
│ ├─┬ @intlify/unplugin-vue-i18n@0.8.1
│ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped invalid: "^9.0.0" from node_modules/vuetify
│ ├─┬ vue-i18n-routing@0.10.2
│ │ ├─┬ @intlify/vue-i18n-bridge@0.8.0
│ │ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped invalid: "^9.0.0" from node_modules/vuetify
│ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped invalid: "^9.0.0" from node_modules/vuetify                                                                                         10:08:19
│ └── vue-i18n@9.3.0-beta.14-77e850b deduped
├── vue-i18n@9.3.0-beta.14-77e850b
└─┬ vuetify@3.1.0
  └── vue-i18n@9.3.0-beta.14-77e850b deduped invalid: "^9.0.0" from node_modules/vuetify
frankrousseau commented 1 year ago

Hello all, I still have the same error with the mentioned dependencies and nuxt 3.2.3:

├─┬ @nuxtjs/i18n@8.0.0-beta.7
│ ├─┬ @intlify/unplugin-vue-i18n@0.8.2
│ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped
│ ├─┬ vue-i18n-routing@0.10.3
│ │ ├─┬ @intlify/vue-i18n-bridge@0.8.0
│ │ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped
│ │ └── vue-i18n@9.3.0-beta.14-77e850b deduped
│ └── vue-i18n@9.3.0-beta.14-77e850b deduped
└── vue-i18n@9.3.0-beta.14-77e850b
kazupon commented 1 year ago

If you have minimal reproduction repo or stackblize, you would open as new issue with it, please. Thanks.