lucsoft / esbuild-plugin-http-imports

persistent cached http import resolution for esbuild
https://deno.land/x/esbuild_plugin_http_imports
Creative Commons Zero v1.0 Universal
11 stars 2 forks source link

Fails to import from esm.sh #4

Closed b3nten closed 1 year ago

b3nten commented 1 year ago

The plugin fails to import from "https://esm.sh/solid-js/web". It works from "https://esm.sh/stable/solid-js@1.7.4/es2022/web.js"

[ERROR] No matching export in "esbuild_serve:http-import:https://esm.sh/solid-js/web" for import "template"

    public/index.js:6:9:
      6 │ import { template as _$template } from "https://esm.sh/solid-js/web";
        ╵          ~~~~~~~~

error: Uncaught Error: Build failed with 1 error:
public/index.js:6:9: ERROR: No matching export in "esbuild_serve:http-import:https://esm.sh/solid-js/web" for import "template"
  let error = new Error(`${text}${summary}`);
              ^
    at failureErrorWithLog (https://deno.land/x/esbuild@v0.15.13/mod.js:1546:15)
    at https://deno.land/x/esbuild@v0.15.13/mod.js:1004:28
    at runOnEndCallbacks (https://deno.land/x/esbuild@v0.15.13/mod.js:1418:61)
    at buildResponseToResult (https://deno.land/x/esbuild@v0.15.13/mod.js:1002:7)
    at https://deno.land/x/esbuild@v0.15.13/mod.js:1114:14
    at responseCallbacks.<computed> (https://deno.land/x/esbuild@v0.15.13/mod.js:651:9)
    at handleIncomingPacket (https://deno.land/x/esbuild@v0.15.13/mod.js:706:9)
    at readFromStdout (https://deno.land/x/esbuild@v0.15.13/mod.js:627:7)
    at https://deno.land/x/esbuild@v0.15.13/mod.js:1828:11
    at eventLoopTick (ext:core/01_core.js:166:11)
lucsoft commented 1 year ago

Sometimes esm.sh is "flaky". does this import work under deno itself?

b3nten commented 1 year ago

Actually I think I know why. https://github.com/lucsoft/esbuild_serve/blob/main/features/httpImports.ts#LL66C13-L69C27 It can't chose an appropriate loader because there isn't a file extension.

lucsoft commented 1 year ago

image

It will fetch depending on the content type, im pretty sure esm.sh will deliver it correctly. Personally i had also some issue with esm.sh lately

lucsoft commented 1 year ago

I tried using the latest version of esbuild_serve and your import works. I'm going to try later if i can reproduce it further.

You could check if it works for you currently:

import { httpImports } from "https://raw.githubusercontent.com/lucsoft/esbuild_serve/85c36a/features/httpImports.ts";

It's the latest version

ije commented 1 year ago

Actually I think I know why. https://github.com/lucsoft/esbuild_serve/blob/main/features/httpImports.ts#LL66C13-L69C27 It can't chose an appropriate loader because there isn't a file extension.

check the content-type header instead

ije commented 1 year ago

image

It will fetch depending on the content type, im pretty sure esm.sh will deliver it correctly. Personally i had also some issue with esm.sh lately

what's your issue? i'm glad to fix 🙏

lucsoft commented 1 year ago

image It will fetch depending on the content type, im pretty sure esm.sh will deliver it correctly. Personally i had also some issue with esm.sh lately

what's your issue? i'm glad to fix 🙏

Oh great to see you :D. Pretty sure the problem was with the npm package mjml-browser which had the issue that the default import was missing. im not sure if its fixed already

ije commented 1 year ago

image It will fetch depending on the content type, im pretty sure esm.sh will deliver it correctly. Personally i had also some issue with esm.sh lately

what's your issue? i'm glad to fix 🙏

Oh great to see you :D. Pretty sure the problem was with the npm package mjml-browser which had the issue that the default import was missing. im not sure if its fixed already

probably it's a problem of the cjs-lexer! i will look into it thanks 👍🙏

b3nten commented 1 year ago

Looks like the fix is appending ?target=esnext to the url. Makes sense, as otherwise esm.sh is targetting Deno. I wonder if there is a way to set the UserAgent header to something that would automatically grab things in esnext format. I don't know if it makes sense as a default though.

headers.append("User-Agent", "es2022") works.

lucsoft commented 1 year ago

im pretty sure your cache just stored an bad import. you could also do ?foo and it should have fixed your problem

ije commented 1 year ago
Screenshot 2023-05-06 at 19 15 18

@lucsoft seems it works for me

lucsoft commented 1 year ago

So yeah can't really reproduce the issue.