Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loader doesn't work with esbuild's stdio option #125

Open
MariusVatasoiu opened this issue Apr 11, 2024 · 3 comments
Open

Loader doesn't work with esbuild's stdio option #125

MariusVatasoiu opened this issue Apr 11, 2024 · 3 comments

Comments

@MariusVatasoiu
Copy link

MariusVatasoiu commented Apr 11, 2024

If I use the stdin option to set the entrypoint, I get the following error:

[ERROR] [assert] namespace is empty [plugin deno-resolver]

    <stdin>:1:7:
      1 │ import "https://deno.land/std@0.185.0/bytes/mod.ts";
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the code snippet used:

import * as esbuild from "npm:esbuild@0.20.2";
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3";

const result = await esbuild.build({
  stdin: {
    contents: `
    import "https://deno.land/std@0.185.0/bytes/mod.ts";
    import "./main.ts";       
    `,
    resolveDir: Deno.cwd(),
  },
  plugins: [...denoPlugins()],
  outfile: "./test.bundle.js",
  bundle: true,
  format: "esm",
});

console.log(result.outputFiles);

esbuild.stop();

Esbuild doesn't set the namespace for stdin entrypoint. The object received by the plugin looks like this:

{
  path: "https://deno.land/std@0.185.0/bytes/mod.ts",
  importer: "<stdin>",
  namespace: "",
  resolveDir: "/Users/...",
  kind: "import-statement",
  pluginData: undefined
}
{
  path: "./main.ts",
  importer: "<stdin>",
  namespace: "",
  resolveDir: "/Users/...",
  kind: "import-statement",
  pluginData: undefined
}

Might be as well an esbuild bug, but not sure if the loader can handle this case.

@lucacasonato
Copy link
Owner

I just have to special case importer == "<stdin>" && namespace == "" to instead use $resolveDir/__stdin.ts as the importer with a namespace of file.

@MariusVatasoiu
Copy link
Author

I also opened an issue on esbuild: evanw/esbuild#3726

@MariusVatasoiu
Copy link
Author

I think one extra check would be args.resolveDir !== "". If you're omitting the resolveDir: Deno.cwd() option, args.resolveDir will be an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants