denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
95.46k stars 5.3k forks source link

BYONM doesn't work in Jupyter notebooks #21308

Open pekam opened 10 months ago

pekam commented 10 months ago

Stepst to reproduce:

  1. Follow the steps in the Deno 1.38 release blog post to create a new npm project and test that importing cowsay from node_modules works with the BYONM flag.
  2. Create a Jupyter notebook file (or start a Jupyter REPL session), and run exactly the same code there (import cowsay from "cowsay";).
  3. Notice the error:
    TypeError: Could not resolve "cowsay", but found it in a package.json. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?

So it seems that the kernel does read the BYONM flag from deno.json and tries to take it into use, but fails to find the npm package in node_modules?

pekam commented 10 months ago

Found a simple workaround: import the npm packages through a deps file.

deps.ts:

import cowsay from "cowsay";
export { cowsay };

notebook:

import { cowsay } from "./deps.ts";
dsherret commented 10 months ago

It seems to work for me. How are you running it and what does your directory structure look like? Did you run npm install or use some other package manager?

I do incorrectly get an error in the lsp though.

image

pekam commented 10 months ago

I'm running the notebook in VS Code, but as said, the same result happens in jupyter REPL (jupyter console --kernel deno).

I followed exactly the steps in the blog post, and after that added a notebook file with the same code. So yes, I used npm install.

Here's my entire project: image

Anyway, it's not a big deal for me since I found a workaround, and if you can't reproduce it, I understand if you have higher priorities. :)