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

Ability to use a local copy of npm package #15624

Open
brc-dd opened this issue Aug 26, 2022 · 10 comments
Open

Ability to use a local copy of npm package #15624

brc-dd opened this issue Aug 26, 2022 · 10 comments

Comments

@brc-dd
Copy link

brc-dd commented Aug 26, 2022

Is there any way to use a local (modified) copy of an NPM package instead of a published one in this command? Thanks!

deno run -A --unstable npm:vite
@dsherret
Copy link
Member

No, it's not something that's possible at the moment, but definitely on our radar. It wouldn't be difficult to implement. It's more a question of how it's specified so if anyone has any ideas let us know.

Maybe like npm:///path/to/local/package/folder, then if you do npm:///path/to/local/package/folder/some/sub_path.js it would resolve the first actual package.json going up the parents (so at /path/to/local/package/folder/package.json) and then resolve the rest of the path (./some/sub_path.js) as a subpath from there. I'm not sure though and there's probably some way that breaks down.

@brc-dd
Copy link
Author

brc-dd commented Aug 26, 2022

For now, I suppose just some way to use tarball would be sufficient, one can just do npm pack and deno run. 🤔

@stale
Copy link

stale bot commented Oct 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@yisibl
Copy link

yisibl commented Feb 7, 2023

Yes, we need the ability to import local packages.

Usage scenario: I am an author of an npm package and I need to test if my npm package works well in deno.

@JonasBa
Copy link

JonasBa commented Apr 17, 2023

+1 here, I am attempting to make test an npm package using native modules in deno and this would have made my life much easier

@JonasBa
Copy link

JonasBa commented Apr 17, 2023

@dsherret mind providing some extra context around this? I might try and find some time to give this a go

@dsherret
Copy link
Member

This one probably requires about 1-2 weeks of work because we'd have to support having multiple paths for what we consider to be "node code" and it introduces a new concept in npm resolution where we need to get package information from the file system instead of just the npm registry and then also make this work with node resolution. I wouldn't recommend it as a first task.

In the meantime, for testing npm packages locally you can use the --node-modules-dir flag to cache an existing version of a package locally and make modifications to it. For example:

> cat main.ts
import CodeBlockWriter from "npm:code-block-writer@12.0.0";
console.log(CodeBlockWriter);
> deno cache --node-modules-dir main.ts
> # overwrite the contents of node_modules/.deno/code-block-writer@12.0.0/node_modules/code-block-writer here and make sure to leave the `.initialized` file
> deno run --node-modules-dir main.ts # this will now use your modifications

@brc-dd
Copy link
Author

brc-dd commented Apr 17, 2023

Something like verdaccio should also work along with NPM_CONFIG_REGISTRY env var 👀

@jedwards1211
Copy link

This would solve the problems with CI testing that npm packages work with Deno: #19621

@alexgleason
Copy link
Contributor

In the meantime, for testing npm packages locally you can use the --node-modules-dir flag to cache an existing version of a package locally and make modifications to it. For example:

I could not get this to work at all until I added a package.json file containing an empty object {} in the same directory. Then it worked.

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

No branches or pull requests

7 participants