lucacasonato / esbuild_deno_loader

Deno module resolution for `esbuild`
https://deno.land/x/esbuild_deno_loader
MIT License
160 stars 43 forks source link

Plugin breaks non-JS/TS code #129

Open NfNitLoop opened 3 months ago

NfNitLoop commented 3 months ago

I'd love to use this to bundle resources that may include Deno code and non-JS code (like CSS/SCSS files).

But adding the plugin to my ESBuild configuration breaks if there are files that aren't TypeScript/JavaScript.

IMO, if this plugin doesn't know how to handle these files, it should just skip them and allow other plugins (or esbuild itself) to handle them.

Reproduction

I've got a minimal reproduction here:

https://github.com/NfNitLoop/deno-loader-bug

With a config like this:

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({
  plugins: [
    // ...denoPlugins()
  ],
  entryPoints: [
    "src/mod.ts",
    "src/style.css",
  ],
  outdir: "dist",
  bundle: true,
  format: "esm",
});
esbuild.stop();

This works, but if you uncomment the denoPlugins() line you get errors:

✘ [ERROR] Expected a JavaScript or TypeScript module, but identified a Unknown module. Importing these types of modules is currently not supported. Specifier: file:///Users/codyc/code/bugs/deno-loader-bug/src/style.css [plugin deno-loader]

NfNitLoop commented 3 months ago

FWIW, I previously rolled my own code that was similar to esbuild-deno-loader, but decided to adopt esbuild-deno-loader to support JSR imports. My loader explicitly only applied to particular kinds of imports (back then, http[s] imports), so it didn't run into this issue. So I expect filtering to just js/ts/jsx/tsx imports here might be a quick fix?