1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(node): cjs pkg dynamically importing esm-only pkg fails (#24730)

This commit is contained in:
David Sherret 2024-07-25 21:40:10 -04:00 committed by GitHub
parent ef38aa9d9c
commit 7907265590
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 53 additions and 4 deletions

View file

@ -221,10 +221,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
specifier, specifier,
referrer, referrer,
referrer_kind, referrer_kind,
match referrer_kind { // even though the referrer may be CJS, if we're here that means we're doing ESM resolution
NodeModuleKind::Esm => DEFAULT_CONDITIONS, DEFAULT_CONDITIONS,
NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
},
mode, mode,
)?; )?;

View file

@ -0,0 +1,7 @@
{
"envs": {
"DENO_FUTURE": "1"
},
"args": "run --check main.ts",
"output": "main.out"
}

View file

@ -0,0 +1,2 @@
Check file:///[WILDLINE]main.ts
3

View file

@ -0,0 +1,4 @@
import { addAsync } from "cjs-add";
const value: number = await addAsync(1, 2);
console.log(value);

View file

@ -0,0 +1,3 @@
import add from "esm-add";
export function addAsync(a: number, b: number): Promise<ReturnType<typeof add>>;

View file

@ -0,0 +1,4 @@
module.exports.addAsync = async (a, b) => {
const add = await import("esm-add");
return add.default(a, b);
};

View file

@ -0,0 +1,3 @@
{
"name": "cjs-add"
}

View file

@ -0,0 +1 @@
export default function add(a: number, b: number): number;

View file

@ -0,0 +1,3 @@
export default function add(a, b) {
return a + b;
}

View 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"
]
}

View file

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