mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(node): cjs pkg dynamically importing esm-only pkg fails (#24730)
This commit is contained in:
parent
ef38aa9d9c
commit
7907265590
11 changed files with 53 additions and 4 deletions
|
@ -221,10 +221,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
|||
specifier,
|
||||
referrer,
|
||||
referrer_kind,
|
||||
match referrer_kind {
|
||||
NodeModuleKind::Esm => DEFAULT_CONDITIONS,
|
||||
NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
|
||||
},
|
||||
// even though the referrer may be CJS, if we're here that means we're doing ESM resolution
|
||||
DEFAULT_CONDITIONS,
|
||||
mode,
|
||||
)?;
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"envs": {
|
||||
"DENO_FUTURE": "1"
|
||||
},
|
||||
"args": "run --check main.ts",
|
||||
"output": "main.out"
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Check file:///[WILDLINE]main.ts
|
||||
3
|
|
@ -0,0 +1,4 @@
|
|||
import { addAsync } from "cjs-add";
|
||||
|
||||
const value: number = await addAsync(1, 2);
|
||||
console.log(value);
|
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts
generated
vendored
Normal file
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import add from "esm-add";
|
||||
|
||||
export function addAsync(a: number, b: number): Promise<ReturnType<typeof add>>;
|
4
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js
generated
vendored
Normal file
4
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
module.exports.addAsync = async (a, b) => {
|
||||
const add = await import("esm-add");
|
||||
return add.default(a, b);
|
||||
};
|
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json
generated
vendored
Normal file
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "cjs-add"
|
||||
}
|
1
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts
generated
vendored
Normal file
1
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export default function add(a: number, b: number): number;
|
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js
generated
vendored
Normal file
3
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default function add(a, b) {
|
||||
return a + b;
|
||||
}
|
21
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json
generated
vendored
Normal file
21
tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "esm-add",
|
||||
"version": "0.12.1",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./index.d.ts",
|
||||
"import": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"files",
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "module"
|
||||
}
|
Loading…
Reference in a new issue