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

Get JSR @datasette/table to work #89

Open
simonw opened this issue Mar 2, 2024 · 3 comments
Open

Get JSR @datasette/table to work #89

simonw opened this issue Mar 2, 2024 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@simonw
Copy link
Owner

simonw commented Mar 2, 2024

As shown in this TIL, I got stuck! https://til.simonwillison.net/javascript/jsr-esbuild

mkdir /tmp/datasette-demo2
cd /tmp/datasette-demo2

echo '@jsr:registry=https://npm.jsr.io' > .npmrc
npm install @jsr/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/@jsr/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 want to run my https://jsr.io/@datasette/table component in a browser, installed via JSR.

Here's what it looks like when it works: https://simonw.github.io/datasette-table/

Code here: https:/simonw/datasette-table/

@simonw simonw added the help wanted Extra attention is needed label Mar 2, 2024
@ThisIsMissEm
Copy link

I wonder if you're needing to manually add dependencies of your dependencies to your project? That seems weird though, but might work

@simonw
Copy link
Owner Author

simonw commented Mar 2, 2024

@JReinhold
Copy link

JReinhold commented Mar 2, 2024

Looks like JSR is adding the npm: protocol/prefix to your lit import automatically when you publish. This is evident when comparing the code on JSR vs what's in your repo.

I assume this is to make your package compatible with Deno, which uses that specifier for Node compatibility: https://docs.deno.com/runtime/manual/node/npm_specifiers

My gut feeling tells me this is a JSR bug/edge case because I don't see this documented anywhere.
The primary use case for JSR is to publish TypeScript source, and then for npm compatibility, JSR will compile that to JavaScript. The TS source will be used by Deno/Bun while the JS dist will be used by Node/browser.

But since you're publishing JavaScript, the "source" and the "dist" is the same file, and so JSR tries to make it compatible with Deno by adding the npm: specifier, but that ironically breaks compatibility with npm.

My gut feeling could be wrong though.

EDIT: Oh wow, while researching and writing this it turns out you reached the same conclusion. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants