karma-esbuild icon indicating copy to clipboard operation
karma-esbuild copied to clipboard

When using file loaders, processResult throws an error

Open thatsmydoing opened this issue 3 years ago • 2 comments

When using an esbuild config with file loaders, the result.outputFiles may contain files other than the sourcemap and resulting js.

This causes an error here https://github.com/marvinhagemeister/karma-esbuild/blob/bcf99827e49c0451feeb27e5bd75c6a5ea049361/src/bundle.ts#L153-L154 when it tries to parse some other file as a sourcemap and fails

thatsmydoing avatar Feb 22 '22 13:02 thatsmydoing

Do you have an example of how to reproduce this? I'm not sure what file loader you're referencing.

jridgewell avatar Feb 23 '22 23:02 jridgewell

I meant this one https://esbuild.github.io/content-types/#external-file

So you could do

import url from "./somefile.txt";

and configure esbuild with

require('esbuild').buildSync({
  entryPoints: ['app.js'],
  bundle: true,
  loader: { '.txt': 'file' },
  outdir: 'out',
})

and it should output both the bundle and the .txt file into out

thatsmydoing avatar Feb 24 '22 12:02 thatsmydoing