Missing src folder with YARN or NPM package install

Viewed 1692

Creating a simple package.json

yarn init

{
  "name": "freedraw",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}

Adding leaflet-freedraw dependency:

yarn add leaflet-freedraw

{
  "name": "freedraw",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "leaflet-freedraw": "^2.13.0"
  }
}

The installed node module only contains this:

/dist
package.json
LICENSE
README.md

There sould also be the source folder installed:

/src

The devs from freedraw say the /src folder should also be there.

I'm using a lot of packages and I get the /src folder everywhere except here. Same happens with npm.

2 Answers

There sould also be the source folder installed

There is no obligation for an author to also publish the src on npm.

As pointed out by Ivan, it looks like the author did configure their package to publish only files in the "dist" folder: (that might be a mistake on their part)

Extract from package.json:

{
  "files": [
    "dist"
  ],
}

https://github.com/Wildhoney/Leaflet.FreeDraw/commit/3b82125994e9676ea018d67bf04a679934bbf5e8

npm doc for package.json "files" field:

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. File patterns follow a similar syntax to .gitignore, but reversed: including a file, directory, or glob pattern (*, **/*, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to ["*"], which means it will include all files.

https://docs.npmjs.com/configuring-npm/package-json.html#files

We are facing a similar issue, and are missing the src/ sub-directory when running a global install of an NPM package from our private NPM registry.

There is nothing referenced in the .npmignore or .gitignore files, and we are even explicitly referencing the src/ sub-directory in files block in the package.json:

{
...
  "main": "./bin/cli.js",
  "bin": {
    "app_name": "./bin/cli.js"
  },
  "scripts": {
    "start": "node ./bin/cli.js"
  },
  "files": [
    "bin",
    "test",
    "src",
    "package.json"
  ],
...
}

Interestingly the install also fails to install the test sub-directory, and moving the entry point to the src/ sub-directory results in it failing to install at all with the following error:

ENOENT: no such file or directory, chmod '...node_modules/@private_registry/app_name/src/cli.js
Related