fix(vite): importing node:* builtins (#3245)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import * as feed from "feed";
|
||||
|
||||
export default function Page() {
|
||||
// deno-lint-ignore no-console
|
||||
console.log(feed);
|
||||
return <h1>feed</h1>;
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
|
||||
"@types/babel__core": "npm:@types/babel__core@^7.20.5",
|
||||
"@types/node": "npm:@types/node@^24.1.0",
|
||||
"feed": "npm:feed@^5.1.0",
|
||||
"mime-db": "npm:mime-db@^1.54.0",
|
||||
"preact": "npm:preact@^10.26.9",
|
||||
"rollup-plugin-visualizer": "npm:rollup-plugin-visualizer@^6.0.3",
|
||||
|
||||
@@ -102,6 +102,13 @@ export function deno(): Plugin {
|
||||
ResolutionMode.Import,
|
||||
);
|
||||
|
||||
if (resolved.startsWith("node:")) {
|
||||
return {
|
||||
id: resolved,
|
||||
external: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (original === resolved) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -322,3 +322,21 @@ Deno.test({
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite build - import node:*",
|
||||
fn: async () => {
|
||||
await using res = await buildVite(DEMO_DIR);
|
||||
|
||||
await launchProd(
|
||||
{ cwd: res.tmp },
|
||||
async (address) => {
|
||||
const res = await fetch(`${address}/tests/feed`);
|
||||
await res.body?.cancel();
|
||||
expect(res.status).toEqual(200);
|
||||
},
|
||||
);
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
@@ -251,3 +251,16 @@ Deno.test({
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "vite dev - import node:*",
|
||||
fn: async () => {
|
||||
await withDevServer(DEMO_DIR, async (address) => {
|
||||
const res = await fetch(`${address}/tests/feed`);
|
||||
await res.body?.cancel();
|
||||
expect(res.status).toEqual(200);
|
||||
});
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user