I have 2 TS packages. project-1
is installed as a dependency in project-2
. I am able to import and access all type definitions of project-1
. But the dependencies (node_modules directory) in project-1
are not found. This is because the node_modules
directory of project-1
is not present. Do I really need to manually npm install
inside that node_modules/project-1
directory? Or should the node_modules directory be published to npm as well? If so, should I remove it from tsconfig.json's
exclude
property? I think node_modules
should be in .gitignore
right?
Just to be clear:
./project-2/node_modules // this exists
./project-2/node_modules/project-1 // this exists
./project-2/node_modules/project-1/node_modules // this does not
/* only after manually running npm install in
* ./project-2/node_modules/project-1 the node_modules folder appears.
*/
project-1 ** package.json**
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "commonjs",
tsconfig.json
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"module": "CommonJS",
"outDir": "dist",
"baseUrl": ".",
"rootDir": "src",
"strict": true,
"target": "ES5",
"noImplicitAny": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.test.ts"]
}
.gitignore
node_modules
dist
logs
tsconfig.tsbuildinfo
.env
.npmignore this file is empty.
How do I ensure that the node_modules directory is present when installing an npm package?
The node_modules directory should not be published to npm registry. It should only contain dependencies installed during the development of your project. To ensure that the node_modules directory is present when installing an npm package, you need to run npm install or yarn install in your project root directory after you have installed your dependencies. The node_modules directory should also be listed in your.gitignore file to avoid committing it to your Git repository.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.