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

Bundler load function not called before throwing #196

Open
WilcoKruijer opened this issue Nov 12, 2024 · 0 comments
Open

Bundler load function not called before throwing #196

WilcoKruijer opened this issue Nov 12, 2024 · 0 comments

Comments

@WilcoKruijer
Copy link

I would expect in the following case that the load function would be called before erroring out of the bundling.

It seems that the documentation of the load method agrees with this:

Override the default loading mechanism with a custom loader. This can provide a way to use "in-memory" resources instead of fetching them remotely.

// repro.ts
import { type CacheSetting, createCache, type LoadResponse } from "jsr:@deno/cache-dir";
import { bundle } from "jsr:@deno/emit";

const bundleCache = createCache({});

const load = (
  specifier: string,
  isDynamic?: boolean,
  cacheSetting?: CacheSetting,
  checksum?: string,
): Promise<LoadResponse | undefined> => {
  if (specifier === "does-not-exist") {
    return Promise.resolve({
      kind: "module",
      specifier,
      content: `export function func() { console.log("hello world"); }`,
    });
  }

  return bundleCache.load(specifier, isDynamic, cacheSetting, checksum);
};

await Deno.writeTextFile(
  "./my-thing.js",
  `
  import { func } from "does-not-exist";
  func();
  `,
);

const { code } = await bundle("./my-thing.js", {
  load,
});

console.log(code);

The code above fails with

 deno run -A repro.ts
error: Uncaught (in promise) Error: Unable to output during bundling: load_transformed failed: failed to analyze module: failed to resolve does-not-exist from file:///Users/wilco/dev/wilcofirst/packages/browser-test-runner/my-thing.js: Cannot resolve "does-not-exist" from "file:///Users/wilco/dev/wilcofirst/packages/browser-test-runner/my-thing.js".
      const ret = new Error(getStringFromWasm0(arg0, arg1));
                  ^
    at __wbg_new_28c511d9baebfa89 (https://jsr.io/@deno/emit/0.46.0/emit.generated.js:557:19)
    at <anonymous> (wasm://wasm/010a1b62:1:3287273)
    at <anonymous> (wasm://wasm/010a1b62:1:429097)
    at <anonymous> (wasm://wasm/010a1b62:1:1820413)
    at <anonymous> (wasm://wasm/010a1b62:1:2928941)
    at __wbg_adapter_46 (https://jsr.io/@deno/emit/0.46.0/emit.generated.js:247:6)
    at real (https://jsr.io/@deno/emit/0.46.0/emit.generated.js:231:14)
    at ext:core/01_core.js:291:9
    at eventLoopTick (ext:core/01_core.js:175:7)
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

1 participant