mcneel / rhino3dm

Libraries based on OpenNURBS with a RhinoCommon style
MIT License
574 stars 135 forks source link

rhino3dm.js incompatible with Node v18. I keep getting error ERR_INVALID_URL #492

Closed dgrcode closed 1 year ago

dgrcode commented 1 year ago

I was getting this issue with 0.14.0. After upgrading to 7.15.0 I keep getting the same error.

TypeError: Failed to parse URL from {project path}/node_modules/rhino3dm/rhino3dm.wasm
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:393:5)
      at URL.onParseError (node:internal/url:565:9)
      at new URL (node:internal/url:645:5)
      at new Request (node:internal/deps/undici/undici:9472:25)
      at Agent.fetch2 (node:internal/deps/undici/undici:10291:25)
      at Object.fetch (node:internal/deps/undici/undici:11116:28)
      at fetch (node:internal/process/pre_execution:216:25)
      at instantiateAsync ({project path}/node_modules/rhino3dm/rhino3dm.js:9:16039)
      at createWasm ({project path}/node_modules/rhino3dm/rhino3dm.js:9:16646)
      at {project path}/node_modules/rhino3dm/rhino3dm.js:9:131229 {
    input: '{project path}/node_modules/rhino3dm/rhino3dm.wasm',
    code: 'ERR_INVALID_URL'
  }
}

I'm not sure what's going on, because the file at {project path}/node_modules/rhino3dm/rhino3dm.wasm is there. I can do cat {project path}/node_modules/rhino3dm/rhino3dm.wasm and see a bunch of binary output.

I think I might have updated node to v18.12.1 before I started seeing this issue. Could this be a node 18 compatibility issue?

I do get this warning when starting the server:

(node:71881) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
dgrcode commented 1 year ago

I can confirm I don't get this issue with node v16.19.0. We'd have to confirm this is a node 18 incompatibility issue. This would be a problem given node releases.

From node's release schedule (link), here's the versions lifetime image

v16 entered maintenance status about 3 months ago, on 2022-10-18. End of life will be 2023-09-11.

dgrcode commented 1 year ago

cross-posted to McNeel YouTrack Application as per CONTRIBUTING.md.

Link: https://mcneel.myjetbrains.com/youtrack/issue/BO-3497/rhino3dm.js-with-Node-18-throws-error-ERRINVALIDURL

sbaer commented 1 year ago

What does the code that loads rhino3dm in your node server look like?

dgrcode commented 1 year ago

This is the code that loads rhino3dm

const rhino3dm = require('rhino3dm')

console.log('rhino3dm: initializing')
/**
 * @type Promise<rhino3dm.RhinoModule>
 */
const rhinoPromise = rhino3dm()
  .then((rhino) => {
    console.log('rhino3dm: loaded')
    return rhino
  })
  .catch((err) => {
    console.log('rhino3dm: error', err)
  })

module.exports = rhinoPromise

Then, I use it like this:

const rhinoPromise = require('./server/services/rhino3dm')

const rhino = await rhinoPromise

But I'm confident that's not the issue, because that exact code works with node v16. It has only stopped working when I updated node to v18

dgrcode commented 1 year ago

Hi @sbaer any news on this? Can we confirm rhino3dm.js is not compatible with Node v18?

fraguada commented 1 year ago

@dgrcode Depending on the version of emscriptem, web assembly compiled code is not compatible with Node v18.1.0 and above. See: https://github.com/emscripten-core/emscripten/issues/16913

Seems there was a patch applied. We need to see how to build rhino3dm with an updated version of emscripten to get the benefit of the patch. https://github.com/emscripten-core/emscripten/pull/16917

In the meantime you can run your scripts in node.js 18.1.0 and above like so: node --no-experimental-fetch index.js

Running in 16.15.0 (at least, haven't checked below) - 18.0.0 works as you'd expect.

dgrcode commented 1 year ago

Awesome, thanks for the details and workaround 🙌

fraguada commented 1 year ago

update: by updating our build tools, this issue is no longer present. We are getting ready to release an update. If you want to test, you can do so my using a recent build of js: https://github.com/mcneel/rhino3dm/suites/11184627947/artifacts/571581718

dgrcode commented 1 year ago

I can confirm the files in the link work as expected. Thanks for fixing this one. Is there an estimate update release date?

fraguada commented 1 year ago

Thanks for testing! We have most everything in place for a release except for testing. Hopefully we can wrap it up in a week or so.

fraguada commented 1 year ago

@dgrcode Just published rhino3dm.js 8.0.0. https://www.npmjs.com/package/rhino3dm

dgrcode commented 1 year ago

Thanks for the heads up! I just upgraded to 8.0.0 and it's working great using node v18

fraguada commented 1 year ago

Thanks for reporting @dgrcode!

dgrcode commented 1 year ago

EDIT: Just opened a new issue https://github.com/mcneel/rhino3dm/issues/521 to track this

Quick question. I just created a 3dm file with the rhino3dm.js library, and it gave me an error when trying to open it with Rhino. It said something like the file had been created with Rhino 8 and it couldn't be opened with Rhino 7. I haven't seen any Rhino 8 available yet.

Is that expected?

fraguada commented 1 year ago

answered in #521