npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Local package's `files` field is not respected

What I Wanted to Do

So, I have folder structure somewhat like below:

├── common
└── services
    └── a

common is a npm package, and services/a also is. I want to import common from services/a without publishing common to npm, so I added following field to the package.json of services/a:

   "devDependencies": {
    "common": "file:../../common",

Also, as I want to only expose build output of common as a module, I have sth like below in the package.json of common.

  "files": [

What I’ve expected was, when I run npm install in services/a folder, only dist folder of common gets installed.

What Happened Instead

Instead, entire folder (including source files and all) got copied to services/a/node_modules/common.

Reproduction Steps

As mentioned above

Details says,

The optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency.

My current suspicion is that files field is only respected in the publishing process. However, I think common still “is installed as a dependency” in services/a's perspective, so I think files field should be respected in this case too. Am I doing anything wrong? Or is there any workaround for this? (My main pain point is that as @types/react of common is included in common/node_modules, services/a's compile process breaks due to duplicate declaration file)

Platform Info

$ npm --versions
$ node -p process.platform

files won’t work for file: dependencies because they get symlinked.

Thanks for the answer. If you don’t mind, I’ve created a PR stating that on the official doc’s files field: