2

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?

Bastiaan
  • 686
  • 1
  • 8
  • 20
  • Are the local dependencies on GitHub? – Alicia Sykes Apr 21 '19 at 23:07
  • I'm trying to do the same thing at the moment and it appears to be working. One gotcha is that you need to run `npm install` after configuring the local dependency so that npm creates a link in your node_modules folder to the local-module. – Dan Aug 07 '19 at 08:42

3 Answers3

4

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

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Alicia Sykes
  • 5,997
  • 7
  • 36
  • 64
1

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"
}
Bastiaan
  • 686
  • 1
  • 8
  • 20
1

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.

Arne
  • 596
  • 5
  • 9