Skip to content

ESM Code Splitting Imports #2489

Closed as not planned
Closed as not planned
@GravlLift

Description

@GravlLift

Apologies if this is a very obvious question, but I couldn't find anything in the docs to explain this:

I'm looking to use esbuild to generate esm formatted output without bundling. As a simple case, I tried this.

a.ts

import { writeBLog } from "./b";
console.log("a.ts");
writeBLog();

b.ts

export function writeBLog() {
  console.log("b.js")
}

esbuild a.ts --outdir=out --format=esm

I was expecting to see both a a.js and b.js file in my out dir. Instead I only get a.js

a.js

import { writeLog } from "./b";
console.log("a.ts");
writeLog();

And of course, that import now refers to a non-existent b.js file.

It seems like esbuild is treating all files as external by default. What setting do I need to set to get esbuild to ouput a b.js file (and any other imports) as well?

EsBuild version 0.15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions