nuxt-modules / robots

Tame the robots crawling and indexing your Nuxt site.
https://nuxtseo.com/robots
MIT License
424 stars 34 forks source link

Runtime error on Windows machines for Nuxt 3 (absolute path must be valid) #99

Closed Xyrai closed 4 months ago

Xyrai commented 1 year ago

Hey there 👋

I am currently experiencing an error on my Windows (11) machine when trying to install the @nuxtjs/robots 3.0.0 package on nuxt 3.6.1.

Error Log

 ERROR  [worker reload] [worker init] Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

  at new NodeError (node:internal/errors:399:5)
  at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
  at defaultResolve (node:internal/modules/esm/resolve:1135:3)
  at nextResolve (node:internal/modules/esm/loader:163:28)
  at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
  at link (node:internal/modules/esm/module_job:76:36)

Node version: 18.15.0

List of things I tried out so far without success:

  1. Using the edge version of Nuxt https://github.com/nuxt/framework/issues/4232#issuecomment-1345385724

  2. Creating a robots.config.ts file https://github.com/nuxt-modules/robots/issues/86#issuecomment-1366121300

Here is a repository containing a replica of the error: https://github.com/Xyrai/nuxt-robots-windows-error/tree/main Additional link to Sandbox, this runs fine since it is not build on a Windows container.

Xyrai commented 1 year ago

Adding a robots.config.ts file to the root of your project now works with Nuxt 3.6.1. Is there any clarification of why adding this file manually fixes the issue, since it is not mentioned in the README.

jrutila commented 1 year ago

Can confirm this happening with nuxt 3.6.1. The workaround of using robots.config.ts works.

alexnguyennz commented 1 year ago

Thanks for this workaround - fixes this issue on 3.6.2.

TheDutchCoder commented 7 months ago

We've just experienced this exact same issue, and the underlying issue was actually the fact that some of our imports in TypeScript required .js extensions, otherwise the resolver would create paths like C:/foo/bar instead of file://C:/foo/bar.mjs in the .nuxt output.

I hope this can help others that run into this nearly undebuggable issue.