DenoDDeno
Powered by
ptatoP
Denoβ€’3y agoβ€’
3 replies
ptato

How to polyfill node imports when bundling with the deno version of esbuild?

Hello,

I am trying to run esbuild using https://deno.land/x/esbuild to bundle a Deno project into a single file. I am using the
denoPlugins
denoPlugins
from https://deno.land/x/esbuild_deno_loader to resolve npm imports, but I need all node std lib imports to be polyfilled as well (which the plugin doesn't do because it assumes youre running the bundle using Deno). My intended compile target is cloudflare workers so i need the node imports to be polyfilled.

I tried using https://www.npmjs.com/package/esbuild-plugin-polyfill-node alongside the
denoPlugins
denoPlugins
but I get the error
Cannot find package '@jspm/core'
Cannot find package '@jspm/core'
.

this is my general setup:
import * as esbuild from "https://deno.land/x/esbuild@v0.20.1/mod.js";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.5/mod.ts";
import { polyfillNode } from "npm:@rivet-gg/esbuild-plugin-polyfill-node@^0.4.0";

await esbuild.build({
    entryPoints: [join(project.path, "_gen", "entrypoint.ts")],
    outfile: join(project.path, "_gen", "/output.js"),
    format: "esm",
    platform: "neutral",
    plugins: [
        ...denoPlugins(),
        polyfillNode(),
    ],
    external: ["*.wasm", "*.wasm?module"],
    bundle: true,
    // minify: true,
});

await esbuild.stop();
import * as esbuild from "https://deno.land/x/esbuild@v0.20.1/mod.js";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.5/mod.ts";
import { polyfillNode } from "npm:@rivet-gg/esbuild-plugin-polyfill-node@^0.4.0";

await esbuild.build({
    entryPoints: [join(project.path, "_gen", "entrypoint.ts")],
    outfile: join(project.path, "_gen", "/output.js"),
    format: "esm",
    platform: "neutral",
    plugins: [
        ...denoPlugins(),
        polyfillNode(),
    ],
    external: ["*.wasm", "*.wasm?module"],
    bundle: true,
    // minify: true,
});

await esbuild.stop();
npm
esbuild-plugin-polyfill-node
ESBuild plugin for polyfilling Node.js builtins for edge and Deno. Latest version: 0.3.0, last published: 9 months ago. Start using esbuild-plugin-polyfill-node in your project by running
npm i esbuild-plugin-polyfill-node
npm i esbuild-plugin-polyfill-node
. There are 17 other projects in the npm registry using esbuild-plugin-polyfill-node.
esbuild-plugin-polyfill-node
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Running esbuild with esbuild_deno_loader
ioBIioB / help
4y ago
Using ESBuild with Deno
MqxMMqx / help
3y ago
Decorators with esbuild-deno-loader
bennypBbennyp / help
11mo ago
Deno 2.4 emit for bundling with "npm:" imports inside code
ErfanEErfan / help
11mo ago