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

Error when using dev-mode in layer #2238

Closed
niklaswolf opened this issue Jul 17, 2023 · 6 comments · Fixed by #2265
Closed

Error when using dev-mode in layer #2238

niklaswolf opened this issue Jul 17, 2023 · 6 comments · Fixed by #2265
Labels
layers ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8

Comments

@niklaswolf
Copy link
Contributor

Environment

  • Operating System: Darwin
  • Node Version: v18.15.0
  • Nuxt Version: 3.6.2
  • Nitro Version: 2.5.2
  • Package Manager: npm@9.5.0
  • Builder: vite
  • User Config: extends, hooks, runtimeConfig, modules, i18n
  • Runtime Modules: modules/domainRuntimeInfo, nuxt-schema-org@2.2.0
  • Build Modules: -

Reproduction

I'll try to provide a repro later

Describe the bug

I use nuxt-i18n edge version (latest version) in a project with a nuxt-layer.
The dev-mode is working in the layer, but not in the project using the layer
When I start the site in dev mode, the following error message shows in the browser

[vite-node] [ERR_INVALID_ARG_VALUE] @nuxtjs/i18n/main/i18n.config.ts&hash=57b8ea29&from=./.nuxt/i18n.options.mjs

When I build both sites (layer and project) and start them in prod mode, both work. So there seems to be something strange in dev-mode when using a nuxt-layer.

Additional context

I18N configuration in both projects (layer and main-project)

i18n: {
    skipSettingLocaleOnNavigate: true,
    differentDomains: true,
    types: 'composition',
    locales: [
      {
        code: 'en-GB',
        file: 'en.json',
        domain: 'www.example.com'
      },
      {
        code: 'de-DE',
        file: 'de.json',
        domain: 'www.example.de
      },
    ],
    compilation: {
      strictMessage: false,
    },
    lazy: false,
    langDir: 'PATH_TO_DIR',
    defaultLocale: 'en-GB',
  },

Logs

No response

Copy link
Collaborator

kazupon commented Jul 19, 2023

Thank you for your reporting!

We need the minimal reproduction to find out the cause.
Could you give us it with stackbliz or github repo, please ? 🙏

@niklaswolf
Copy link
Contributor Author

@kazupon finally found the time to make a reproduction.
Here you go: https://github.com/niklaswolf/nuxt-i18n-reproduction

@niklaswolf
Copy link
Contributor Author

I think I found the place where the NULL byte is added: https://github.com/nuxt-modules/i18n/blob/next/src/gen.ts#L182
its the genDynamicInput function. I modified the code a bit into seperate variables and found this when logging it:

@nuxtjs/i18n:gen importSpecifier  @nuxtjs/i18n/__config__?target=../i18n.config.ts&hash=da2031ea 

@nuxtjs/i18n:gen dynamicImportSpecifier  () => import("\u0000@nuxtjs/i18n/__config__?target=../i18n.config.ts&hash=da2031ea" /* webpackChunkName: "i18n_config_da2031ea" */) 

@niklaswolf
Copy link
Contributor Author

Okay I think I tracked this down 🥳
I'll try to explain using code references:

asVirtualId is called here
https://github.com/nuxt-modules/i18n/blob/next/src/gen.ts#L307C35-L307C46

It adds \0 as a prefix: https://github.com/nuxt-modules/i18n/blob/next/src/transform/utils.ts#L16

genDynamicImport from knitwork uses JSON.stringify internally, see https://github.com/unjs/knitwork/blob/main/src/string.ts#L3

If you run JSON.stringify("\0asdf") in node, you get '"\\u0000asdf"'

@kazupon kazupon added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage and removed need reproduction 💻 labels Jul 24, 2023 — with Volta.net
Copy link
Collaborator

kazupon commented Jul 24, 2023

@niklaswolf
Thank you for your reproduction!
And your track code explanation is so helpful for us.
So, I'll try to fix this issue.

Maybe, this issue is also related to #2242

Copy link
Collaborator

kazupon commented Jul 26, 2023

This issue is same #2242.
It cause that the import IDs dynamically generated by nuxt i18n by vite are not being resolved correctly.
The error is different from #2242, but the root cause is the same.

@kazupon kazupon added ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf and removed 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Jul 26, 2023 — with Volta.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
layers ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants