nuxt-modules / i18n

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

Issue with Nuxt 3 Layers and Nuxt i18n with remote layer #2491

Open SGDS-SyL opened 1 year ago

SGDS-SyL commented 1 year ago

Running into the same issue as discussion, Layer works locally but when changed to Github repo. It failed with this:

Failed to resolve import "/lang/en.json" from ".nuxt\i18n.options.mjs" I've checked and the file do exist.

Discussed in https://github.com/nuxt-modules/i18n/discussions/2388

Originally posted by **ionutfrent** September 8, 2023 ### Issue Description **Package Name/Repository:** Nuxt 3 with Layers **Nuxt i18n Version:** "@nuxtjs/i18n": "v8.0.0-rc.4" ### Issue Details I am currently working with Nuxt 3 Layers for my project. When I extend Layers from local repositories, everything works perfect. However, when I try to extend Layers from a GitHub repository link, I encounter an issue with the Nuxt i18n package. The specific error message I'm getting is: `ERROR No lockfile found from /***/node_modules/base-app` _**It's important to note that I have the latest version of "@nuxtjs/i18n" (v8.0.0-rc.4) installed in all Layers.**_ ### Steps to Reproduce To reproduce this issue, follow these steps: - Create a Nuxt 3 project as a base Layer. - Use Nuxt i18n in the base Layer. - Push the project to a GitHub repository. - Create a Nuxt 3 project which extends the base Layer from the GitHub repository link. - Install the dependencies. _**The base-app layer is added as a dependency in package.json as follows:**_ `"dependencies": { "base-app": "git+ssh://github_pat_***@github.com:***/base-app.git" }` ### Expected Behavior I expected the project to run without errors when extending Layers from a GitHub repository while using the latest version of Nuxt i18n. ### Actual Behavior Instead, I encountered the "No lockfile found" error as described above. ### Additional Notes I'd like to highlight that the described issue appears to be introduced in the latest versions of the library. To provide some context, I experimented with an alpha version of the library, and I couldn't reproduce the issue. This suggests that there might be a regression or compatibility issue in the most recent releases of the library, specifically affecting projects using Nuxt 3 Layers in conjunction with Nuxt i18n. cc/ @kazupon I would appreciate any assistance or insights from the community or individuals experienced with Nuxt 3 Layers and Nuxt i18n.
github-actions[bot] commented 1 year ago

Would you be able to provide a reproduction? πŸ™

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: πŸ‘‰ [Reproduction starter (v8 and higher)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/v8) πŸ‘‰ [Reproduction starter (edge)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/edge) A public GitHub repository is also perfect. πŸ‘Œ Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)
derHodrig commented 1 year ago

Thank you for opening an issue.

Just to inform as written in the discussion: "@nuxtjs/i18n": "8.0.0-beta.4" solves the installation error (every newer version breaks) but with that version all translations in the layer need to move to the application.

BobbieGoede commented 1 year ago

I would like to look into this issue but I will need a minimal reproduction to debug the exact issue. πŸ˜…

Nuxt 3.8.0 has layer improvements which may tackle the underlying issue here.

derHodrig commented 1 year ago

Reproduction Steps

  1. Checkout https://github.com/derHodrig/nuxt-i18n-reproduction
  2. navigate to i18n-app
  3. run npm install

Install should fail

Note: Both, Layer and App do not have any configuration in their nuxt.config.ts, because the issue is in the installation of the layer. You should observe this error:

npm ERR!  ERROR  No lockfile found from ...\i18n-reproduction\i18n-app\node_modules\@skoenfeld\i18n-layer
npm ERR!
npm ERR!   at resolveLockfile (.../i18n-reproduction/i18n-app/node_modules/pkg-types/dist/index.mjs:122:9)
npm ERR!   at async getPackageManagerType (.../i18n-reproduction/i18n-app/node_modules/@nuxtjs/i18n/dist/module.mjs:108:26)

its my first reproduction, feel free to improve me via critics ^^

BobbieGoede commented 1 year ago

@derHodrig I believe the issue you're experiencing is because the layer runs nuxt prepare because of the npm postinstall script, but lockfiles are not published in npm packages. Can you try removing the postinstall script and check if it works again? And of course I recommend installing the edge release channel as it includes most recent bug fixes!

its my first reproduction, feel free to improve me via critics ^^

It's a good reproduction! As it is an npm package it is a bit hard to make changes and test, but that's something inherent to this specific issue πŸ˜…

derHodrig commented 12 months ago

@BobbieGoede did not think that this problem is that simple solved.

@SGDS-SyL could you please rename your postinstall script in your layer>package.json and install the new published layer? https://github.com/derHodrig/nuxt-i18n-reproduction/commit/4c88663f56c81028919cd83580be86a9fdbfce4e#diff-b68b7af82dbabeceff18a29ef8697de0c088349cd1b2a4f0a872ec92095c7802

In my case, in the reproduction, the issue was solved.

Downturn is, after your install deps in the layer, you have to manually use the nuxt prepare .playground

BobbieGoede commented 12 months ago

In my case, in the reproduction, the issue was solved.

Glad to hear the issue was solved for you!

Downturn is, after your install deps in the layer, you have to manually use the nuxt prepare .playground

Hmm, have you tried updating the module to the latest edge release and seeing if the error is still thrown when keeping the postinstall script?

npm ERR!   at async getPackageManagerType (.../i18n-reproduction/i18n-app/node_modules/@nuxtjs/i18n/dist/module.mjs:108:26)

I believe the code that is throwing this error has been removed and is not present in the edge release.