-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Bring your own node_modules for incremental Deno adoption #18967
Comments
This is a nice idea, but it would be very challenging to do given Deno's current architecture. Deno works completely off of npm specifiers, and relies on knowing the npm resolution upfront. Ex. even if there's a package.json, that all gets transformed under the hood to npm specifiers. It would take a lot of effort to implement this and it might just be more worthwhile investing that into Edit: Also, we would need to consider what happens when the user adds a package and doesn't then run |
In this scenario wouldn't deno have that available based on the node_modules structure on disk? Alternatively, could even use the existing package-lock.json which has it all included.
I don't think implementing those helps in the incremental adoption use-case as deno will mess with the local node_modules: #18803 It only works that way if deno owns the full workspace node_modules, etc. which will be a tougher sell to add to existing projects. |
Deno doesn't understand how to read a node_modules folder to figure out resolution or to read an existing package-lock.json at the moment, which is why this would be a lot of work.
Ideally, the node_modules folder is unnecessary and already many packages work without it. We could also investigate only modifying the |
This makes `CliNpmResolver` a trait. The terminology used is: - **managed** - Deno manages the node_modules folder and does an auto-install (ex. `ManagedCliNpmResolver`) - **byonm** - "Bring your own node_modules" (ex. `ByonmCliNpmResolver`, which is in this PR, but unimplemented at the moment) Part of #18967
This makes `CliNpmResolver` a trait. The terminology used is: - **managed** - Deno manages the node_modules folder and does an auto-install (ex. `ManagedCliNpmResolver`) - **byonm** - "Bring your own node_modules" (ex. `ByonmCliNpmResolver`, which is in this PR, but unimplemented at the moment) Part of #18967
Just a note that I've been actively working on this the past few weeks. Current thought on how this should work:
So this would be a breaking change. We're thinking to land it even before Deno 2.0. Initially it will land under an unstable flag/config value. |
How about non-breaking |
It would be ideal for most Node projects to just work without additional setup instructions, so to achieve that it would have to be breaking. |
That sounds awesome! I'm excited about having that capability. I had one thought that could be interesting from a "deno runs your npm packages more securely" perspective. It could be nice to have the ability to say what the top-level node_module directory allowed during npm module resolution is. For example if I have:
from The file I'll admit it's a not a problem I've run into in practice (that I've noticed) but it's a quirk of node_module resolution I always found a bit odd. |
) This PR adds a new unstable "bring your own node_modules" (BYONM) functionality currently behind a `--unstable-byonm` flag (`"unstable": ["byonm"]` in a deno.json). This enables users to run a separate install command (ex. `npm install`, `pnpm install`) then run `deno run main.ts` and Deno will respect the layout of the node_modules directory as setup by the separate install command. It also works with npm/yarn/pnpm workspaces. For this PR, the behaviour is opted into by specifying `--unstable-byonm`/`"unstable": ["byonm"]`, but in the future we may make this the default behaviour as outlined in #18967 (comment) This is an extremely rough initial implementation. Errors are terrible in this and the LSP requires frequent restarts. Improvements will be done in follow up PRs.
@dsherret I'm finding "Bring your own node_modules" to be valuable for another reason: mixing public and private NPM registries by scope My company publishes some packages only via private registry, which requires authentication. So we instruct customers to set up an Under that configuration, I saw in Deno's configuration documentation (here and here) that it's possible to change the registry that is used for retrieving packages (and, if memory serves, add authentication). And that worked--but it resulted in all packages being resolved through that registry, which is not workable. So I wondered if, in Deno's progress toward deeper NPM compatibility, it might eventually provide per-scope registry configuration, like However, now seeing this "Bring your own node_modules", it seems like this would eliminate the need for per-scope registry config. |
I get the error below importing Plotly.js-dist. The Cache content is the same as in an npm node_modules dir with a project that works. (The deno pl import works fine as does d3). Is there an invocation to make it work? Or is it a current deno limitation? If a limitation, please add Plotly.js to the list. Much used in data science, e.g. with pandas and polars.
|
@gplanansky see #21836 |
@dsherret with |
I am still unable to import plotly.js in Deno. I believe I know why. index.html:
myplotly.js:
The above works fine. However the plotly.js node import needs a subscription token, without which npm imports fail.
Question -- how to use the cdn library, in Deno? Deno being a Jupyter kernel, it would be nice to use the js plotly library alongside the js polars etc libraries in a notebook. |
This issue might be superseded by #23151 |
As a node developer I'm excited about incrementally introducing Deno to exisiting projects. If Deno allowed an operating mode where I can use it in an existing single npm module project or npm workspace monorepo with my exisiting npm workflows to manage my npm dependencies that would be a HUGE for incremental adoption.
I appreciate deno trying to solve the problems with npm, but right now lack of local file: support, workspace support, build reproducibility, etc. are just blocking me from exploring deno in most projects besides one-off tools.
I would love to have a
deno --bring-your-own-node-modules
flag that used thenpm:
import specifier and just resolved the npm package using the package resolution algorithm locally on disk without trying to fetch dependencies, create links / junctions, update lock files, etc.To be straightforward, I think the permissions model is useful, and I want to use it as quickly as possible. Improving the npm tooling is great but not what attracts me to deno. The permissions model + sandbox, focus on web standards compatibility,
@deno_land
, are what I want to start using and sharing.This would let me stick Deno in the thick of large projects by swapping out node tooling incrementally. I could migrate the scripts using the exisiting node_modules, package.json, package-lock.json, etc managed by npm itself for the whole workspace. Even makes it easier to just test deno support with npm packages without introducing whole new workflows to patch npm packages locally, etc.
The text was updated successfully, but these errors were encountered: