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

Something rewrote my import to from 'npm:lit@^2.2.7'; and now I can't build with esbuild #139

Closed
simonw opened this issue Mar 2, 2024 · 5 comments · Fixed by #172
Closed
Assignees
Labels
bug Something isn't working

Comments

@simonw
Copy link

simonw commented Mar 2, 2024

My original source code here: https:/simonw/datasette-table/blob/0.1.0/datasette-table.js

import {LitElement, html, css} from 'lit';

After I published it to jsr.io it was rewritten like this: https://jsr.io/@datasette/table/0.1.0/datasette-table.js

import {LitElement, html, css} from 'npm:lit@^2.2.7';

But now when I try to install it and run it through esbuild I get an error:

mkdir /tmp/datasette-demo
cd /tmp/datasette-demo
npx jsr add @datasette/table
echo 'import * as mod from "jsr:@datasette/table";' > index.js
npx esbuild index.js --bundle --outfile=bundle.js

Error:

✘ [ERROR] Could not resolve "npm:lit@^2.2.7"

    node_modules/@datasette/table/datasette-table.js:1:36:
      1 │ import {LitElement, html, css} from 'npm:lit@^2.2.7';
        ╵                                     ~~~~~~~~~~~~~~~~

  You can mark the path "npm:lit@^2.2.7" as external to exclude it from the bundle, which will
  remove this error and leave the unresolved path in the bundle.

1 error

I asked in Discord and marvinh said: https://discord.com/channels/684898665143206084/1203185670508515399/1213595537505521664

Esbuild doesn't understand npm: or jsr: . That's a Deno only thing. So your source code should not have import specifiers with these prefixes anywhere. That said the lit error looks like a bug. That should've been transpiled away

More of my notes here: https://til.simonwillison.net/javascript/jsr-esbuild

@simonw
Copy link
Author

simonw commented Mar 2, 2024

@dsherret
Copy link
Member

dsherret commented Mar 2, 2024

The jsr tool should not be pulling in npm specifiers. That's a bug. The specifier at https://jsr.io/@datasette/table/0.1.0/datasette-table.js is correct, but the specifier in node_modules/@datasette/table/datasette-table.js is wrong. It should be "lit"

@dsherret dsherret added the bug Something isn't working label Mar 2, 2024
@marvinhagemeister marvinhagemeister self-assigned this Mar 4, 2024
@lucacasonato
Copy link
Member

The fix is in #172

github-merge-queue bot pushed a commit that referenced this issue Mar 4, 2024
We previously only transpiled ts sources, but we need to transpile js
sources as well to be able to rewrite imports like turning `import ...
from "npm:lit@^2.2.7"` into `import ... from "lit";`.

Fixes #139
@simonw
Copy link
Author

simonw commented Mar 6, 2024

Thanks, this works for me now! Notes here: https://til.simonwillison.net/javascript/jsr-esbuild#user-content-and-now-it-works

@marvinhagemeister
Copy link
Contributor

Thanks for updating the blog post. Yeah it was just a bug on our end. Happy to see it resolved 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants