Skip to content

Commit 55e16a7

Browse files
add 2.3 updates for local node modules (#1669)
Co-authored-by: Phil Hawksworth <phil@deno.com>
1 parent 95cdbe2 commit 55e16a7

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

runtime/fundamentals/modules.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,38 @@ Limitations:
329329

330330
### Overriding NPM packages
331331

332-
We plan to support NPM packages with the patch functionality described above,
333-
but until then if you have a `node_modules` directory, `npm link` can be used
334-
without change to accheive the same effect. This is typically done with
335-
`{ "nodeModulesDir": "manual" }` set in the `deno.json` file. See also the
336-
documentation on [`node_modules`](/runtime/fundamentals/node/#node_modules)
332+
Deno supports patching npm packages with local versions, similar to how JSR
333+
packages can be patched. This allows you to use a local copy of an npm package
334+
during development without publishing it.
335+
336+
To use a local npm package, configure the `patch` field in your `deno.json`:
337+
338+
```json
339+
{
340+
"patch": [
341+
"../path/to/local_npm_package"
342+
],
343+
"unstable": ["npm-patch"]
344+
}
345+
```
346+
347+
This feature requires a `node_modules` directory and has different behaviors
348+
depending on your `nodeModulesDir` setting:
349+
350+
- With `"nodeModulesDir": "auto"`: The directory is recreated on each run, which
351+
slightly increases startup time but ensures the latest version is always used.
352+
- With `"nodeModulesDir": "manual"` (default when using package.json): You must
353+
run `deno install` after updating the package to get the changes into the
354+
workspace's `node_modules` directory.
355+
356+
Limitations:
357+
358+
- Specifying a local copy of an npm package or changing its dependencies will
359+
purge npm packages from the lockfile, which may cause npm resolution to work
360+
differently.
361+
- The npm package name must exist in the registry, even if you're using a local
362+
copy.
363+
- This feature is currently behind the `unstable` flag.
337364

338365
### Overriding HTTPS imports
339366

0 commit comments

Comments
 (0)