lucacasonato / esbuild_deno_loader

Deno module resolution for `esbuild`
https://jsr.io/@luca/esbuild-deno-loader
MIT License
176 stars 46 forks source link

imports map not working #86

Closed swwind closed 10 months ago

swwind commented 1 year ago

I don't think the resolver handles import maps correctly.

deno.json

{
  "imports": {
    "path": "https://deno.land/std@0.201.0/path/mod.ts"
  }
}

mod.ts

import { join } from "path";

console.log(join("foo", "bar"));

build.ts

import * as esbuild from "https://deno.land/x/esbuild@v0.17.9/mod.js";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts";

await esbuild.build({
  plugins: [...denoPlugins()],
  entryPoints: ["./mod.ts"],
  bundle: true,
  outdir: "./build",
});

when running deno run -A build.ts, I got

✘ [ERROR] Module not found "file:///home/swwind/Repositories/deno_esbuild_test/path". [plugin deno-loader]

    mod.ts:1:21:
      1 │ import { join } from "path";
        ╵                      ~~~~~~

error: Uncaught (in promise) Error: Build failed with 1 error:
mod.ts:1:21: ERROR: [plugin: deno-loader] Module not found "file:///home/swwind/Repositories/deno_esbuild_test/path".
  let error = new Error(`${text}${summary}`);
              ^
    at failureErrorWithLog (https://deno.land/x/esbuild@v0.17.9/mod.js:1612:15)
    at https://deno.land/x/esbuild@v0.17.9/mod.js:1024:25
    at runOnEndCallbacks (https://deno.land/x/esbuild@v0.17.9/mod.js:1447:45)
    at buildResponseToResult (https://deno.land/x/esbuild@v0.17.9/mod.js:1022:7)
    at https://deno.land/x/esbuild@v0.17.9/mod.js:1051:16
    at responseCallbacks.<computed> (https://deno.land/x/esbuild@v0.17.9/mod.js:673:9)
    at handleIncomingPacket (https://deno.land/x/esbuild@v0.17.9/mod.js:728:9)
    at readFromStdout (https://deno.land/x/esbuild@v0.17.9/mod.js:649:7)
    at https://deno.land/x/esbuild@v0.17.9/mod.js:1898:11
    at eventLoopTick (ext:core/01_core.js:183:11)

while deno run mod.ts just works.

swwind commented 1 year ago

this looks like

  1. I did not provide configPath as './deno.json', but i think this should be the default config path
  2. toFileUrl will throw if configPath is not a absolute path. https://github.com/lucacasonato/esbuild_deno_loader/blob/d360c108ac03c4f22843e9673471c6232f3d7507/src/plugin_deno_resolver.ts#L68-L71
lucacasonato commented 10 months ago

I think this is working as intended. Feel free to open a PR to improve the error message, but this is what the docs also say.