0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-08 07:16:56 -05:00

fix(node): resolve module as maybe CJS when it's missing a file extension (#27904)

This commit is contained in:
Rano | Ranadeep 2025-02-01 19:12:17 +01:00 committed by GitHub
parent 9cbcb84295
commit 540fe7d9e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 1 deletions

View file

@ -274,7 +274,7 @@ impl<TInNpmPackageChecker: InNpmPackageChecker, TSys: FsRead>
self.pkg_json_resolver.get_closest_package_json(&path)?
{
let is_file_location_cjs = pkg_json.typ != "module";
Ok(if is_file_location_cjs {
Ok(if is_file_location_cjs || path.extension().is_none() {
ResolutionMode::Require
} else {
ResolutionMode::Import

View file

@ -0,0 +1,4 @@
{
"args": "run main.mts",
"output": "3\n"
}

View file

@ -0,0 +1,3 @@
import { add } from "package/add";
console.log(add(1, 2));

View file

@ -0,0 +1 @@
module.exports.add = require("./internal.cjs").add;

View file

@ -0,0 +1 @@
module.exports.add = (a, b) => a + b;

View file

@ -0,0 +1,3 @@
{
"type": "module"
}

View file

@ -0,0 +1 @@
{}