I want to do something like this, so npm install
also installs the package.json
of ../somelocallib
or more importantly its dependencie
Actually, as of npm 2.0, there is support now local paths (see here).
I know that npm install ../somelocallib
works.
However, I don't know whether or not the syntax you show in the question will work from package.json
...
Unfortunately, doc seems to only mention URL as a dependency.
Try file:///.../...tar.gz
, pointing to a zipped local lib... and tell us if it works.
It is now possible to specify local Node module installation paths in your package.json
directly. From the docs:
Local Paths
As of version 2.0.0 you can provide a path to a local directory that contains a package. Local paths can be saved using
npm install -S
ornpm install --save
, using any of these forms:../foo/bar ~/foo/bar ./foo/bar /foo/bar
in which case they will be normalized to a relative path and added to your
package.json
. For example:{ "name": "baz", "dependencies": { "bar": "file:../foo/bar" } }
This feature is helpful for local offline development and creating tests that require npm installing where you don't want to hit an external server, but should not be used when publishing packages to the public registry.
Here is the package.json you will use for the master project:
"dependencies": {
"express": "*",
"somelocallib": "file:./somelocallib"
}
There, ./somelocallib
is the reference to the library folder as relative to the master project package.json.
Reference: https://docs.npmjs.com/files/package.json#local-paths
Handle your library dependencies.
In addition to running npm install
, you will need to run (cd node_modules/somelocallib && npm install)
.
This is a known bug with NPM.
Reference: https://github.com/npm/npm/issues/1341 (seeking a more up-to-date reference)
Check in your master package.lock
and your somelocallib/package.lock
into your source code manager.
Then in your Dockerfile use:
FROM node:10
WORKDIR /app
# ...
COPY ./package.json ./package-lock.json ./
COPY somelocallib somelocallib
RUN npm ci
RUN (cd node_modules/zkp-utils/ && npm ci)
# ...
I use parenthesis in my (cd A && B)
constructs to make the operation idempotent.
Two steps for a complete local development:
Curious.....at least on Windows (my npm is 3.something) I needed to do:
"dependencies": {
"body-parser": "^1.17.1",
"module1": "../module1",
"module2": "../module2",
When I did an npm install ../module1 --save
it resulted in absolute paths and not relative per the documentation.
I messed around a little more and determined that ../xxx
was sufficient.
Specifically, I have the local node modules checked out to say d:\build\module1, d:\build\module2 and my node project (application) in d:\build\nodeApp.
To 'install', I:
d:\build\module1> rmdir "./node_modules" /q /s && npm install
d:\build\module2> rmdir "./node_modules" /q /s && npm install
d:\build\nodeApp> rmdir "./node_modules" /q /s && npm install
module1's package.json has a dependency of "module2": "../module2"; module2 has no local dependency; nodeApp has dependencies "module1": "../module1" and "module2": "../module2".
Not sure if this only works for me since all 3 folders (module1, module2 and nodeApp) sit on that same level.......