mcneel / rhino3dm

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

[ERROR] Could not resolve "ws" #612

Open hopezh opened 1 month ago

hopezh commented 1 month ago

I got the following error while running the example code rhino3dm.js.

I don't know how to ...mark the path "ws" as external to exclude it from the bundle, as suggested in the error message.

May I ask if I have missed something important here?

npm run dev

> threejs_starter_v01@0.0.0 dev
> vite

  VITE v5.2.8  ready in 169 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: http://192.168.138.1:5173/
  ➜  Network: http://192.168.70.1:5173/
  ➜  Network: http://192.168.12.121:5173/
  ➜  press h + enter to show help

✘ [ERROR] Could not resolve "ws"

    node_modules/rhino3dm/rhino3dm.js:9:64363:
      9 │ ...ocketServer=require("ws").Server;var host=so...
        ╵                        ~~~~

  You can mark the path "ws" as external to exclude it from
  the bundle, which will remove this error and leave the
  unresolved path in the bundle. You can also surround this
  "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

6:16:26 pm [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/rhino3dm/rhino3dm.js:9:64363: ERROR: Could not resolve "ws"
    at failureErrorWithLog (C:\Users\aaa\Downloads\code\threejs_starter_v01\node_modules\esbuild\lib\main.js:1651:15)
    at C:\Users\aaa\Downloads\code\threejs_starter_v01\node_modules\esbuild\lib\main.js:1059:25
    at C:\Users\aaa\Downloads\code\threejs_starter_v01\node_modules\esbuild\lib\main.js:1527:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The output of my npm list:

+-- rhino3dm@8.6.0
+-- three@0.163.0
`-- vite@5.2.8
fraguada commented 1 month ago

Please try with rhino3dm@8.4.0 as there is an issue with 8.6.0. I've since deprecated 8.6.0 and made 8.4.0 latest.

fraguada commented 1 month ago

I am preparing an 8.6.1 release for js. If you can test this package, I would really appreciate it: https://github.com/mcneel/rhino3dm/actions/runs/9017758138/artifacts/1487757185

fraguada commented 1 month ago

https://www.npmjs.com/package/rhino3dm/v/8.6.1 has been published which should resolve this issue. Please let me know if that is not the case.

hopezh commented 1 month ago

Thanks, @fraguada.

I still got the following error while running the example code on the latest npm repo of rhino3dm, and the test code is in this repo.

(BTW, I init the test repo with npm create vite@latest.)

Error

npm run dev

> test_rhino3dm_js@0.0.0 dev
> vite

  VITE v5.2.11  ready in 217 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
✘ [ERROR] Could not resolve "ws"

    node_modules/rhino3dm/rhino3dm.js:9:64363:
      9 │ ...r(26)},listen:function(sock,backlog){if(!ENVIRONMENT_IS_NODE){throw new FS.ErrnoError(138)}if(sock.server){throw new FS.ErrnoError(28)}var WebSocketServer=require("ws").Server;var host=sock.saddr;sock.server=new WebSocketServer({host:host,port:sock.sport});Module["websocket"].emit("listen",sock.stream.fd);sock.server.on("connec...
        ╵                                                                                                                                                                       ~~~~

  You can mark the path "ws" as external to exclude it from the bundle, which will remove this error
  and leave the unresolved path in the bundle. You can also surround this "require" call with a
  try/catch block to handle this failure at run-time instead of bundle-time.

my npm list:

> npm list

test_rhino3dm_js@0.0.0 C:\Users\jizha\Downloads\code\test_rhino3dm_js
+-- rhino3dm@8.6.1
`-- vite@5.2.11
fraguada commented 1 month ago

Unfortunately I don't know anything about vite, so don't know how to help. I'll try running vite to see if I can figure out the issue.