After creating a Typescript package and publishing it on NPM, I encountered an issue with the declaration files not being included in the published version. Despite setting declaration: true
in the tsconfig.json
, only the JavaScript files were being published, leading to errors when trying to install the package in another project.
Below is my package.json file configuration:
{
"name": "@Organisation/lib",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
//removed for brevity
},
"keywords": [],
//remaining configuration removed
}
Along with that, here is an excerpt from my tsconfig.json file:
{
//compilerOptions details removed
}
I also included a .gitignore file to exclude certain directories and files from the repository, but noticed that even though the dist directory was being ignored, the index.js file within it was still getting published, while the .d.ts files were left out.
The structure of the directory looks like this:
my-package/
├─ node_modules/
├─ dist/
│ ├─ models/
│ ├─ index.d.ts
│ ├─ index.js
│ ├─ index.js.map
├─ src/
│ ├─ models
│ ├─ index.ts
├─ .gitignore
├─ package.json
├─ tsconfig.json