deno icon indicating copy to clipboard operation
deno copied to clipboard

Auto enable `byonm` for Node.js projects

Open littledivy opened this issue 1 year ago • 0 comments

Consider the default Next.js app example. A user has to know what "byonm" is to be able to run the project with Deno:

deno run -A npm:create-next-app@13 && cd my-app/

echo "{'unstable':['byonm', 'node-bare-builtins']}" >> deno.json 

deno task dev

Running deno task dev without the proper features enabled will cause Deno to download node modules in global cache, leading to unexpected errors like:

divy@mini ~/g/my-app (main)> deno task dev
Task dev next dev
error: npm package '@next/swc' does not exist.
error: Uncaught (in promise) TypeError: Unknown signal: 0
    at toDenoSignal (ext:deno_node/internal/child_process.ts:282:11)
    at ChildProcess.kill (ext:deno_node/internal/child_process.ts:196:53)
    at handleSessionStop (file:///Users/divy/gh/my-app/node_modules/.deno/[email protected]/node_modules/next/dist/cli/next-dev.js:83:15)
    at ChildProcess.<anonymous> (file:///Users/divy/gh/my-app/node_modules/.deno/[email protected]/node_modules/next/dist/cli/next-dev.js:265:23)
    at ChildProcess.emit (ext:deno_node/_events.mjs:383:28)
    at ext:deno_node/internal/child_process.ts:180:16
    at eventLoopTick (ext:core/01_core.js:65:7)

There are a few ways we could do this:

  1. Default to BYONM behaviour if package.json or node_modules exists.

  2. Detect packages installed in node_modules and use BYONM. Use global cache behaviour for packages that are not installed.

  3. Add subcommand similar to npm install that will install to local node_modules/ if package.json exists and enable BYONM.

  4. Do nothing & Try to improve the error message.

littledivy avatar Feb 07 '24 04:02 littledivy