`ERR_INVALID_URL` running Javascript decoder in Node v18
Running
const draco3d = require("draco3d");
Promise.resolve(draco3d.createDecoderModule({}));
throws an ERR_INVALID_URL error:
~ node /Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/lib/debugg.js
{ decoderModulePromise: Promise { <pending> } }
(node:81439) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/deps/undici/undici:4816
throw new TypeError("Failed to parse URL from " + input, { cause: err });
^
TypeError: Failed to parse URL from /Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder.wasm
at new Request (node:internal/deps/undici/undici:4816:19)
at Agent2.fetch2 (node:internal/deps/undici/undici:5544:29)
... 4 lines matching cause stack trace ...
at Object.createDecoderModule (/Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder_nodejs.js:39:247)
at Object.<anonymous> (/Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/lib/debugg.js:4:52)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:377:5)
at URL.onParseError (node:internal/url:563:9)
at new URL (node:internal/url:643:5)
at new Request (node:internal/deps/undici/undici:4814:25)
at Agent2.fetch2 (node:internal/deps/undici/undici:5544:29)
at Object.fetch (node:internal/deps/undici/undici:6372:20)
at fetch (node:internal/bootstrap/pre_execution:199:25)
at /Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder_nodejs.js:39:1
at /Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder_nodejs.js:39:224
at Object.createDecoderModule (/Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder_nodejs.js:39:247) {
input: '/Users/danvas/.nvm/versions/node/v18.1.0/lib/node_modules/gltf-pipeline/node_modules/draco3d/draco_decoder.wasm',
code: 'ERR_INVALID_URL'
}
}
Node.js v18.1.0
Works fine in Node v17.
edit: I deleted the content of this comment because it was completely wrong and could potentially waste someone's time.
FWIW I am able to reproduce this with the example as it currently is stored within the repository. Node 16 works fine, but node 18 always reports the same error when attempting to load draco_decoder.wasm.
It doesn't matter how the path is structured: Node 18 cannot find the wasm file. Rel path, absolute path, complete URL: same error. We'll have to look into this more deeply. For now I don't have a suggestion other than avoiding use of node 18 with Draco if possible.
You can work around this issue by adding the "--no-experimental-fetch" command line flag.
This issue might be related to https://github.com/emscripten-core/emscripten/pull/16917
You can work around this issue by adding the "--no-experimental-fetch" command line flag.
This works for me, but avoid the silly mistake I made when I was verifying it: the flag must be before the module on the node command line.