Skip to content

fix(node): classify required js files as commonjs by default#34673

Merged
littledivy merged 1 commit into
mainfrom
orch/divybot-399
Jun 1, 2026
Merged

fix(node): classify required js files as commonjs by default#34673
littledivy merged 1 commit into
mainfrom
orch/divybot-399

Conversation

@divybot

@divybot divybot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Treat ambiguous project .js files loaded through require() as CommonJS first unless the nearest package scope is explicitly "type": "module". This matches Node behavior for files like Angular/Karma's karma.conf.js in package scopes with no type field.

Add a regression spec for requiring a Karma-shaped config file from a package with no type field, and update existing require-from-package coverage for the new default while preserving extensionless CJS behavior in "type": "module" packages.

Tests:

  • deno run --allow-write --allow-read --allow-run --allow-net ./tools/format.js --check
  • cargo fmt --check
  • cargo check -p deno_resolver -p deno_node -p deno
  • cargo build -p deno
  • ./x test-spec tests/specs/node/import_cjs_file_no_ext_mjs_pkg tests/specs/run/npm_pkg_requires_esm_js tests/specs/node/require_js_package_no_type
  • /Users/divy/orch-work/issue-399/target/debug/deno run -A main.js (from tests/specs/run/npm_pkg_requires_esm_js)
  • /Users/divy/orch-work/issue-399/target/debug/deno run main.mts (from tests/specs/node/import_cjs_file_no_ext_mjs_pkg)
  • /Users/divy/orch-work/issue-399/target/debug/deno run -A main.cjs (from tests/specs/node/require_js_package_no_type)

Closes #27392
Closes denoland/divybot#399

@littledivy
littledivy merged commit 453eaf6 into main Jun 1, 2026
137 checks passed
@littledivy
littledivy deleted the orch/divybot-399 branch June 1, 2026 18:02
littledivy added a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…d#34673)

Treat ambiguous project .js files loaded through require() as CommonJS
first unless the nearest package scope is explicitly "type": "module".
This matches Node behavior for files like Angular/Karma's karma.conf.js
in package scopes with no type field.

Add a regression spec for requiring a Karma-shaped config file from a
package with no type field, and update existing require-from-package
coverage for the new default while preserving extensionless CJS behavior
in "type": "module" packages.

Tests:
- deno run --allow-write --allow-read --allow-run --allow-net
./tools/format.js --check
- cargo fmt --check
- cargo check -p deno_resolver -p deno_node -p deno
- cargo build -p deno
- ./x test-spec tests/specs/node/import_cjs_file_no_ext_mjs_pkg
tests/specs/run/npm_pkg_requires_esm_js
tests/specs/node/require_js_package_no_type
- /Users/divy/orch-work/issue-399/target/debug/deno run -A main.js (from
tests/specs/run/npm_pkg_requires_esm_js)
- /Users/divy/orch-work/issue-399/target/debug/deno run main.mts (from
tests/specs/node/import_cjs_file_no_ext_mjs_pkg)
- /Users/divy/orch-work/issue-399/target/debug/deno run -A main.cjs
(from tests/specs/node/require_js_package_no_type)

Closes denoland#27392
Closes denoland/divybot#399

Co-authored-by: divybot <[email protected]>
Co-authored-by: Divy Srivastava <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The ng test command fails in Angular when using Deno

2 participants