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

[NEXT] Crashes on rc.9 and rc.10 Only file and data URLs are supported by the default ESM loader #1518

Closed
1 of 2 tasks
warflash opened this issue Sep 15, 2022 · 16 comments
Closed
1 of 2 tasks
Assignees
Labels
🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8

Comments

@warflash
Copy link
Contributor

Version

@nuxtjs/i18n: @nuxtjs/i18n@8.0.0-alpha.1-27710980.d1ee9d2
nuxt: 3.0.0-rc.9

Nuxt configuration

Please change to [x] if relevant for this issue:

  • Applies to a site deployed to a static server (site generated with nuxt generate)
  • Applies to a site deployed to a server with a Node backend

Reproduction Link

I tried updating from rc8 to rc9 today and got the error message below when trying to start in dev mode.
Tried deleting .nuxt, node_modules as well as package-lock.json to get a fresh install but it all resulted in the same error. Same story for rc10 and edge rc11.

https://github.com/warflash/nuxt_7426

Steps to reproduce

Clone the repo on windows and run npm run dev

What is Expected?

The instance starts as normal

What is actually happening?

500
Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'f:'

at new NodeError (node:internal/errors:371:5)
at defaultResolve (node:internal/modules/esm/resolve:1016:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
at ModuleWrap. (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36)
@kazupon kazupon added the v8 label Sep 16, 2022 — with Volta.net
@warflash
Copy link
Contributor Author

For reference, that's the nuxt teams take on the issue: nuxt/nuxt#14877

Nice spot. This is a bug in i18n; it generates some code with an absolute import:

import locale_en from "C:/nuxt_7426/locales/en.json";
export const localeCodes = ["en"]

export const localeMessages = {
  "en": () => Promise.resolve(locale_en),
}

This needs to be instead:

import locale_en from "file:///C:/nuxt_7426/locales/en.json";
export const localeCodes = ["en"]

export const localeMessages = {
  "en": () => Promise.resolve(locale_en),
}

@warflash
Copy link
Contributor Author

Hey @kazupon,

just wondering if you happen to have a rough estimate on this one? It's blocking us from upgrading our nuxt rc version so we're still stuck on rc8 which is kind of unfortunate since there have been a ton of critical fixes since then.
If it's not something that can be resolved anytime soon then that's cool as well of course, but a rough timeframe would be nice so we can plan ahead appropriately.

Thank you and thanks for your awesome work! 🔥

Copy link
Collaborator

kazupon commented Sep 23, 2022

I'm resolving this issue with file protocol, but, I'm a bit stuck with vite why not being able to resolve it 😞

@warflash
Copy link
Contributor Author

warflash commented Sep 23, 2022

Awesome, thank you - well that's good news then! I'm pretty New to vite and the whole tooling as well so unfortunate I cant comment much on that. Maybe daniel would be able to give advice in this issue though 🙏

@so1ve
Copy link
Contributor

so1ve commented Oct 6, 2022

How is it now? I'm stuck with the same problem, my project won't be able to access either page without adding the lazy: true option. However, lazy: true again seems to cause the hydration to fail, producing a whole bunch of warnings.

@huang-julien
Copy link
Contributor

huang-julien commented Oct 13, 2022

Hi ! it only happens with window for me. A workaound is to run the project on WSL (install + dev/build). I hope this can help !

@mnlj
Copy link

mnlj commented Oct 20, 2022

What I don't understand here is what is the point of absolute path. I thought that was generally considered a bad practice? I have the same issue on lastest Nuxt rc.12 and @nuxtjs/i18n 8.0.0-alpha.3.

[nuxt] [request error] [unhandled] [500] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

Generated file .nuxt/i18n.options.mjs contains

import locale_hu from "c:/some/project/i18n/json/hu.json";
import locale_i18n from "c:/some/project/i18n/json/i18n.json";
import locale_pl from "c:/some/project/i18n/json/pl.json";

I've manually hacked the function generateLoaderOptions in node_modules/@nuxtjs/i18n/dist/module.mjs to change the output to

import locale_hu from "../i18n/json/hu.json" assert { type: "json" };
import locale_i18n from "../i18n/json/i18n.json" assert { type: "json" };
import locale_pl from "../i18n/json/pl.json" assert { type: "json" };

and nuxt loads just fine, with i18n working.

I had to add the assert part because without it theres another issue:

[nuxt] [request error] [unhandled] [500] Module "file:///c:/some/project/i18n/json/hu.json" needs an import assertion of type "json"

So, why not use relative paths? Also the function to generate import, genImport, from dependency knitwork, doesn't know how to handle import with assert { type: "json" } so that might need some replacing too.

@Phundrak
Copy link

I had to add the assert part because without it theres another issue:

[nuxt] [request error] [unhandled] [500] Module "file:///c:/some/project/i18n/json/hu.json" needs an import assertion of type "json"

I am very unfamiliar with Windows (haven’t touched it in years), so I might say something stupid, but shouldn’t the path begin with file://c:/ instead of file:///c:/?

@mnlj
Copy link

mnlj commented Oct 25, 2022

I am very unfamiliar with Windows (haven’t touched it in years), so I might say something stupid, but shouldn’t the path begin with file://c:/ instead of file:///c:/?

This has nothing to do with Windows, RFC 1738 defines file url as file://<host>/<path>, and since that is on localhost, it becomes file:///. Also this is very offtopic to anything in this issue.

Copy link
Collaborator

kazupon commented Nov 3, 2022

I've just released @nuxtjs/i18n-edge@8.0.0-beta.3-27791028.494116d edge version
I believe this issue is fixed.
you can try to use it.

@MrSociety404
Copy link

The absolute path issue seems to work but I have now an new issue with the assert type

Module "file:///d:/nuxt3/locales/en-US.json" needs an import assertion of type "json"

@so1ve
Copy link
Contributor

so1ve commented Nov 4, 2022

currently knitwork does not seem to support generating type assertions :-(

Copy link
Collaborator

kazupon commented Nov 4, 2022

I'll push the PR that is supported import assertions on knitwork

Copy link
Collaborator

kazupon commented Nov 12, 2022

I've just support import assertions for import (static).
You can try to use with edge version.

@Aareksio
Copy link

@kazupon Testing with just released beta.5, the vueI18n option set to string does not translate properly on Windows still:

// .nuxt/i18n.options.mjs
export const resolveNuxtI18nOptions = async (context) => {
  const nuxtI18nOptions = Object({})
  const vueI18nOptionsLoader = async (context) => import("X:/path/to/config/vue-i18n").then(r => (r.default || r)(context))
  // ...
}

@kazupon kazupon added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage and removed bug 🐛 labels Dec 8, 2022 — with Volta.net
Copy link
Collaborator

kazupon commented Jul 20, 2023

I think this issue has already fixed latest version so far.
If you have still this issue, please you can open the issue as new.

Thanks!

@kazupon kazupon closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
DarthGigi pushed a commit to DarthGigi/i18n that referenced this issue Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8
Projects
None yet
Development

No branches or pull requests

8 participants