denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.44k stars 5.37k forks source link

Deno 2 panicked running npm cli #25738

Closed reggi closed 1 month ago

reggi commented 1 month ago

I was curious if deno could run the npm cli. I changed the cli/bin/npm-cli.js file to cli/bin/npm-cli.cjs and changed the shebang and I got a panic. Obviously this was just a goof, but just wanted to report the panic.

➜  example RUST_BACKTRACE=full lnpm install lodash
npm verbose cli deno /Users/reggi/Documents/GitHub/cli/bin/npm-cli.cjs
npm info using npm@10.8.3
npm info using node@v20.11.1
npm verbose title npm install lodash
npm verbose argv "install" "lodash"
npm verbose logfile logs-max:10 dir:/Users/reggi/.npm/_logs/2024-09-19T15_59_03_218Z-
npm verbose logfile /Users/reggi/.npm/_logs/2024-09-19T15_59_03_218Z-debug-0.log

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 2.0.0-rc.3
Args: ["deno", "-A", "/Users/reggi/Documents/GitHub/cli/bin/npm-cli.cjs", "install", "lodash"]

thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.310.0/modules/map.rs:1223:24:
internal error: entered unreachable code
stack backtrace:
   0:        0x10341fbc8 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h41035ce174e31160
   1:        0x10254a214 - core::fmt::write::h7e946826fce7616b
   2:        0x1033f0a78 - std::io::Write::write_fmt::he3645adfefb23e4a
   3:        0x103422588 - std::sys_common::backtrace::print::h2efe9ae66fda73dc
   4:        0x103421ea0 - std::panicking::default_hook::{{closure}}::hd27200b4fbd3bf40
   5:        0x103421aa8 - std::panicking::default_hook::hb8656334461229c8
   6:        0x102444ce0 - deno::setup_panic_hook::{{closure}}::h711f7c3abae3b89b
   7:        0x103422e78 - std::panicking::rust_panic_with_hook::h10171cf76e1aed15
   8:        0x1034228d0 - std::panicking::begin_panic_handler::{{closure}}::h9344de43a47cae21
   9:        0x103422864 - std::sys_common::backtrace::__rust_end_short_backtrace::h55013ada3ab9c4e8
  10:        0x103422858 - _rust_begin_unwind
  11:        0x1025486f0 - core::panicking::panic_fmt::h0b16bb09366e1f01
  12:        0x102549f28 - core::panicking::panic::h61ea408fdd25f03d
  13:        0x102647c34 - deno_core::modules::map::ModuleMap::mod_evaluate_sync::ha7ff371654d5c7db
  14:        0x102686c58 - deno_core::ops_builtin::op_import_sync::op_import_sync::v8_fn_ptr::ha8f5bbba425a885a
bartlomieju commented 1 month ago

CC @devsnek looks similar to the previous require(esm) panic.

@reggi FYI you can execute npm fine in deno like so: deno run npm:npm

reggi commented 1 month ago

@bartlomieju I know 🤣, feel free to close

bartlomieju commented 1 month ago

Yeah, it was probably fixed in https://github.com/denoland/deno_core/pull/910, just waiting on deno_core upgrade here.

reggi commented 1 month ago

Same panic with deno run npm:npm:

 example deno run -A npm:npm install lodash
npm verbose cli npm /Users/reggi/example/node_modules/.deno/npm@10.8.3/node_modules/npm/bin/npm-cli.js
npm info using npm@10.8.3
npm info using node@v20.11.1
npm verbose node symlink /Users/reggi/.nvm/versions/node/v22.5.1/bin/npm
npm verbose title npm install lodash
npm verbose argv "install" "lodash"
npm verbose logfile logs-max:10 dir:/Users/reggi/.npm/_logs/2024-09-19T16_09_18_178Z-
npm verbose logfile /Users/reggi/.npm/_logs/2024-09-19T16_09_18_178Z-debug-0.log

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 2.0.0-rc.3
Args: ["deno", "run", "-A", "npm:npm", "install", "lodash"]

thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.310.0/modules/map.rs:1223:24:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note: people should use deno add npm:lodash

devsnek commented 1 month ago

Yes it should be fixed with a deno_core upgrade. The mystery to me is why something in npm would be hitting require(esm), which is still experimental in node.

reggi commented 1 month ago

@devsnek afaik we don't use require(esm) i put together a check esm deps script https://gist.github.com/reggi/68be8cf9a80f1545e67d0fca0402d696

that will print out package deps with type module and without exports["."].require

Dependency: chalk is ESM only Dependency: is-cidr is ESM only Dependency: supports-color is ESM only

which is why we import() these ^^