Npm pack to include local modules

6.1k Views Asked by At

I have some local modules that I want to include in my package to be sent to a server. Since these local packages are not on the npm registry, they need to be part of the package.

I have tried some ways to get the node_modules folder included in the package using npm pack, however it seems this is not possible at all?

Secondly I tried to list the local modules in the bundledDepencies in the package.json file and use npm pack, however this also does not include the local modules, no matter what;

{
    "name": "dev",
    "version": "1.0.0",
    "main": "main.js",
    "dependencies": {
        "local-module": "file:../../local-module"
    },
    "bundledDependencies": [
        "local-module"
    ]
}

How can I get these local modules included in the dev package?

The local module does contain dependencies itself, not sure if that makes things more complicated?

3

There are 3 best solutions below

0
On BEST ANSWER

I had a similar issue a while back, and a good and simple solution, is just to put your local modules into private git repos (which are now free on GitHub, thanks Microsoft )

Then, in your package.json, just add:

"dependencies" : {
  "name1" : "git://github.com/user/project.git#commit-ish",
  "name2" : "git://github.com/user/project.git#commit-ish"
}

Source, npm docs

0
On

I believe Alicia's approach is the cleanest one. However for someone that runs into the same issue as I did, whereby a server requires a tarball, but does not have git installed, I added my local packages to a seperate folder in the project called repo and referenced them in the package.json as;

"dependencies": {
  "my-local-package": "file:./repo/my-local-package"
}
0
On

There's also yalc, which creates a local store for local packages. After adding a local package to the store, you can use yalc to copy the local package into another package. You can also use it to do updates of local packages.