jsr-io / jsr

The open-source package registry for modern JavaScript and TypeScript
https://jsr.io
MIT License
2.29k stars 100 forks source link

[BUG] Imports not being properly deprefixed from `npm:` #640

Open aleksasiriski opened 2 months ago

aleksasiriski commented 2 months ago

I'm building a SvelteKit adapter and am trying to publish it on jsr.io, is uses two imports:

Both of those when uploaded to jsr.io get changed to:

Only the esbuild one when pulled via pnpm dlx jsr add @hearchco/sveltekit-adapter-aws gets changed back to original:

This is causing my SvelteKit built to error out with,  and if I manually change it to original in the node_modules the build is successful:

> Using sveltekit-adapter-aws
✘ [ERROR] Could not resolve "npm:@sveltejs/kit@^2.5.18/node/polyfills"

    .svelte-kit/sveltekit-adapter-aws/server/lambda-handler/index.js:5:33:
      5 │ import { installPolyfills } from 'npm:@sveltejs/kit@^2.5.18/node/polyfills';
        ╵                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "npm:@sveltejs/kit@^2.5.18/node/polyfills" as external to exclude it from
  the bundle, which will remove this error and leave the unresolved path in the bundle.

error during build:
Error: Build failed with 1 error:
.svelte-kit/sveltekit-adapter-aws/server/lambda-handler/index.js:5:33: ERROR: Could not resolve "npm:@sveltejs/kit@^2.5.18/node/polyfills"
    at failureErrorWithLog (/var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:1472:15)
    at /var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:945:25
    at /var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:897:52
    at buildResponseToResult (/var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:943:7)
    at /var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:970:16
    at responseCallbacks.<computed> (/var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/var/home/aleksa/Documents/Projects/Personal/Hearchco/frontend/node_modules/.pnpm/esbuild@0.23.0/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
 ELIFECYCLE  Command failed with exit code 1.
lucacasonato commented 1 month ago

You can workaround this by specifying handler as one of the exports in your jsr.json.

aleksasiriski commented 1 month ago

Since "handler" is a adapter for SvelteKit it "imports" some files that don't exist in the repo but will exist after being copied into the SvelteKit build folder, and this breaks publishing on JSR: https://github.com/hearchco/sveltekit-adapter-aws/actions/runs/9910061704/job/27379574375#step:7:10

lucacasonato commented 1 month ago

Ah I see - then for the moment, as a workaround, you can try renaming the file to handler/index.js.txt (no .js file extension). This will stop the rewriting from happening at all.

Definitely a bug during publishing on our side.

aleksasiriski commented 1 month ago

Hmm, but then I would need to rename it back to .js for SvelteKit to to use properly? I think it's better to wait for the fix instead of using workarounds :) If you point me in the right direction I would be happy to look at this codebase and try to find and fix the bug.

aleksasiriski commented 1 week ago

Any updates on this?