Matthew Schwartz
Matthew Schwartz

Reputation: 45

npm module missing files after publish

For reference, the repo is https://github.com/microsoftly/luis-response-builder.

The node module files are generated with tsc and output to the dist folder. I have a prepublishOnly step that removes the dist folder, runs tsc, then runs the test against the transpiled js. The tests pass when I publish just fine.

The problem is, when I install the project anywhere else, the dist folder contains only the file with the path dist/src/index.js.

I cannot for the life of me figure out why the file is missing when installed but not when published.

Upvotes: 4

Views: 5078

Answers (2)

Patrick Roberts
Patrick Roberts

Reputation: 51876

Quoting from npm-publish Documentation:

All files in the package directory are included if no local .gitignore or .npmignore file exists. If both files exist and a file is ignored by .gitignore but not by .npmignore then it will be included.

Your repository's .gitignore file contains the following:

node_modules
dist
*.env
yarn-error.log

Since dist is being ignored, it's not committed with npm publish, as per the documentation.

Upvotes: 6

trs
trs

Reputation: 349

Check out the package.json documentation about files.

Since you haven't included the files key, it will only include the file specified in main (along with some other default files).

The files value is an array so you can include multiple files and/or folders.

eg:

files: [
  "dist",
  "config/somefile.js"
]

Upvotes: 4

Related Questions