element-plus-nuxt icon indicating copy to clipboard operation
element-plus-nuxt copied to clipboard

Failed to parse URL: [cause]: URL is not a constructor

Open ericktreichel opened this issue 9 months ago • 2 comments

Hi everyone, I am facing an error sometimes when loading or realoading my application in development. Actually, I believe it happened in production a few times, but I didnt pay attention in the logs at that time, so I can't confirm. I noted it happens more in development when I am restart my App and I already have some Tab open in my browser with some url that is not the root of the site/app (/). For instance, if restart my app and I have http://localhost:4000/somepage opened, it will be realoaded automaticaly when the app restart, and will trigger the error I mentioned. I believe this error is related with the @element-plus/nuxt module, but I am not sure.

My machine/project: Node v20.18.1 @element-plus/nuxt: 1.1.1 element-plus: 2.9.7 Nuxt: 3.16..1 Vue: 3.5.13 VS Code version: Code - Insiders 1.99.0-insider (dc289883be5d37d5d2b2f7d30926aa42a3123437, 2025-03-21T19:26:48.394Z) OS version: Windows_NT x64 10.0.26120 Modes: Remote OS version: Linux x64 6.13.8-WSL2-STABLE+

This is the error I get: `[Vue Router warn]: uncaught error during route navigation:

ERROR [GET] "http://127.0.0.1:42457/nuxt_vite_node/module//node_modules/element-plus/es/index.mjs": Failed to parse URL from http://127.0.0.1:42457/nuxt_vite_node/module//node_modules/element-plus/es/index.mjs

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async $fetchRaw2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:270:14)
at async $fetch2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:316:15)
at async Object.fetchModule (node_modules/@nuxt/vite-builder/dist/runtime/vite-node.mjs:47:14)
at async ViteNodeRunner.directRequest (node_modules/vite-node/dist/client.mjs:277:46)
at async ViteNodeRunner.cachedRequest (node_modules/vite-node/dist/client.mjs:206:14)
at async ViteNodeRunner.dependencyRequest (node_modules/vite-node/dist/client.mjs:259:12)
at async components/AudioRecorder.vue:8:31
at async ViteNodeRunner.runModule (node_modules/vite-node/dist/client.mjs:401:5)
at async ViteNodeRunner.directRequest (node_modules/vite-node/dist/client.mjs:381:5)

[cause]: Failed to parse URL from http://127.0.0.1:42457/nuxt_vite_node/module//node_modules/element-plus/es/index.mjs

  at node:internal/deps/undici/undici:13392:13
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async $fetchRaw2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:258:26)

[cause]: URL is not a constructor

    at new Request (node:internal/deps/undici/undici:9474:25)
    at fetch (node:internal/deps/undici/undici:10203:25)
    at fetch (node:internal/deps/undici/undici:13390:10)
    at fetch (node:internal/bootstrap/web/exposed-window-or-worker:72:12)
    at node_modules/ofetch/dist/node.mjs:26:58
    at $fetchRaw2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:258:32)
    at onError (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:179:16)
    at $fetchRaw2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:270:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async $fetch2 (node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:316:15)`

Image

ericktreichel avatar Mar 24 '25 15:03 ericktreichel

COMPLEMENTING MY INFO: http://127.0.0.1:34893/__nuxt_vite_node__/module//node_modules/element-plus/es/index.mjs @jw-foss @foxted This is possible the problem! That path has two slashs between module and node_modules, and it should be one, I suppose. I am not sure how to fix it in the code, but would be nice to see someone fixing. Looks like an easy fix for people who already deal with the lib code. Thanks!

ericktreichel avatar Mar 25 '25 19:03 ericktreichel

The @element-plus/nuxt does not reference the file element-plus/es/index.mjs.

You can check if there are any manual references to element-plus in your project.

tolking avatar Mar 27 '25 06:03 tolking