Currently, I am developing a TypeScript module that relies on another TypeScript-based project called winston
.
The types for winston
are bundled in an index.d.ts
file, and there is no @types/winston
package available as a "devDependency".
From what I gather, the typescript
dependency should be under devDependencies
since it is not needed at runtime. On the other hand, winston
should be in the dependencies
section as it will be used during runtime.
However, when I run npm install --only=dev
, the winston
package is not installed. This leads to compilation errors with tsc
due to missing types (
error TS2307: Cannot find module 'winston'
).
Even if I manage to workaround this issue, it's evident that I cannot access the typings of the package during TypeScript compilation because they were not downloaded.
So, what is the recommended approach here? Should every TypeScript-bundled package providing its own types be placed in the devDependencies
section of package.json
? But then, what about npm install --production
which would skip this dependency and cause runtime failures?
I experimented by adding winston
to both devDependencies
and dependencies
in package.json
. However, running npm install --only=dev
does not download packages listed under dependencies
(not sure if intended or a bug in npm).
package.json
{
"name": "tst",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^12.7.4",
"typescript": "^3.6.2"
},
"dependencies": {
"winston": "^3.2.1"
}
}
test.ts
import * as winston from "winston";
const logger = winston.someMethod();