nodebox-runtime icon indicating copy to clipboard operation
nodebox-runtime copied to clipboard

Cannot find module '/nodebox/npm'

Open lebrunel opened this issue 1 year ago • 1 comments

Should npm just work as expected within the nodebox? Whenever I try to run any npm command, I get an error saying npm is not available.

For example, if I init the nodebox with a simple package.json with a dev script, when I run:

const info = await sh.runCommand('npm', ['dev'])

I get the error:

{
    "code": "MODULE_NOT_FOUND",
    "parent": "/nodebox/index.js",
    "filepath": "/nodebox/npm",
    "message": "Cannot find module '/nodebox/npm' from '/nodebox/index.js'",
    "name": "Error",
    "stack": "Error: Cannot find module '/nodebox/npm' from '/nodebox/index.js'\n    at _0x16e72a.internalResolveSync (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1216259)\n    at _0x16e72a.resolveSync (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1218044)\n    at _0x4cdf65 (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1218585)\n    at _0x4007f6.resolveModule (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1238851)\n    at _0x4007f6.load (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1240113)\n    at _0xfde67f.loadEsModule (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:1246657)\n    at _0x17376b (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:2329245)\n    at MessagePort._0x4c72c8 (https://nodebox-runtime.codesandbox.io/worker-686mf2jx5zo3t9z5wedt8t80gxsi6jq.js:105:2328259)"
}

Just wondering if this is a bug, or if there's something I'm meant to do to make npm available as a command?

lebrunel avatar Jul 09 '24 10:07 lebrunel

I'm running into it as well. I found this:

We don't emulate npm, we leave it up to higher level users like sandpack to implement that the npm logic for now. https://github.com/Sandpack/nodebox-runtime/issues/33#issuecomment-1494275287

Using .runCommand('vite', ['build']) directly gets farther, but I'm still getting snagged about missing modules, so I think there is some magic in Sandpack that makes it work.

alexgleason avatar Jul 19 '25 20:07 alexgleason