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

import from node_modules failing #1234

Closed
borango opened this issue Apr 12, 2024 · 8 comments · Fixed by #1236
Closed

import from node_modules failing #1234

borango opened this issue Apr 12, 2024 · 8 comments · Fixed by #1236
Labels
documentation Improvements or additions to documentation

Comments

@borango
Copy link

borango commented Apr 12, 2024

According to https://observablehq.com/framework/imports#node-imports I should be able to import a lib which I had previously installed via npm i lib.

Expected behaviour

  1. cd into a Framework project
  2. run npm i canvas-confetti
  3. run npm run dev
  4. add a doc page named confetti.md with following content
```js
import confetti from "canvas-confetti"
```

```js
Inputs.button("Throw confetti! 🎉", {reduce: () => confetti()})
```
  1. navigate to http://127.0.0.1:3000/confetti
  2. click button to throw confetti

Observed behaviour

At step 5, I get 2 red lines of error messages:

TypeError: The specifier “canvas-confetti” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
RuntimeError: The specifier “canvas-confetti” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.

I can verify the npm-installed lib both as an entry in package.json "canvas-confetti": "^1.9.2",
and as a separate folder (with expected content) in node_modules/canvas-confetti/

I tried deleting the cache and restarting the dev server.

Variant A

It works when I change the import in confetti.md to import confetti from "npm:canvas-confetti" (adding the npm:).

Variant B

I am observing the same failure for other libraries as well.

@borango borango added the bug Something isn’t working label Apr 12, 2024
@Fil
Copy link
Contributor

Fil commented Apr 12, 2024

See #360; this is fixed in main (see https://github.com/observablehq/framework/commits/main/src/node.ts), but we haven't released a new version yet. A version badge is missing in the documentation.

@Fil Fil added documentation Improvements or additions to documentation and removed bug Something isn’t working labels Apr 12, 2024
@Fil
Copy link
Contributor

Fil commented Apr 12, 2024

(congratulations for getting issue #1234! 🔢 🎯)

Fil added a commit that referenced this issue Apr 12, 2024
@Fil Fil closed this as completed in #1236 Apr 12, 2024
Fil added a commit that referenced this issue Apr 12, 2024
@borango
Copy link
Author

borango commented Apr 13, 2024

(congratulations for getting issue #1234! 🔢 🎯)

Right, this was fun to see.

Thanks a lot for your quick response @Fil .

From my end I cannot confirm that this bug is solved, because I still get the same error. So far I am not building Framework from main but installed it via npm init @observablehq.

Which release should I track so that I can npm update (or perform other action that is needed)?

Thank you for you help. Observable is awesome.

@Fil
Copy link
Contributor

Fil commented Apr 13, 2024

Releases are published on npm and documented here. We hope to ship 1.6 next week or the week after. If you want to use the main branch, you can edit your project’s package.json and set:

"@observablehq/framework": "https://github.com/observablehq/framework#main",

then run npm i.

@mbostock
Copy link
Member

I wouldn’t recommend installing from main as @Fil suggests (since that has other gotchas). I would just wait until we release this feature.

@borango
Copy link
Author

borango commented Apr 13, 2024

Thanks Mike.

To bei fair: @Fil just reported that the fix is implemented in main and I was asking out of curiousity. I appreciate the hint how I could fetch from main if I were desperate enough. Perhaps next time ;-) This time I will wait for R 1.6

Oh, and we arrived at the release-from-main-procedure because my bug ticket is closed and I was wondering how I would obtain the result. From a customer's point of view, in the sense of Incident Management, the situation is not resolved for me. But I guess you are using these Github issues more to track your internal work than to implement Service Management. Fair enough.

@mbostock
Copy link
Member

mbostock commented Apr 13, 2024

From our perspective, the only issue was in the documentation, which as of #1236 now correctly notes that the feature is not yet released. That is why this issue is closed.

We won’t track an issue if a customer is trying to use a feature that’s not yet released. We don’t support features until they are released.

@borango
Copy link
Author

borango commented Apr 14, 2024

You are my hero, @mbostock . I don't argue with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants