ts-node ignores d.ts files while tsc successfully compiles the project
Starting with ts-node in 7.0.0, does not Load files from tsconfig.json
on startup. Instead, you should specificy --files
like this
ts-node --files src/boot.ts
Here's How i fixed it. Add "nodemon --exec ts-node --files src/app.ts" to your dev script.
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon --exec ts-node --files src/app.ts",
"build": "tsc -p",
"test": "echo \"Error: no test specified\" && exit 1"
},
TLDR
Add "ts-node": { "files": true },
in tsconfig.json
for ts-node-dev
to work as expected
explanation:
I was using ts-node-dev
in package.json
like:
"scripts": {
"build": "tsc",
...
"dev": "ts-node-dev src/index.ts"
},
npm run build
was working fine but npm run dev
was failing, My type definition files are in src/types/*
.
It started working fine after I added the following in my tsconfig.json
{
"ts-node": { "files": true }, // add this
"compilerOptions": {
...
}
}
I was having a similar problem, but I could not add --files
, because I run ts-node
by registering the module through mocha
(i.e. mocha -r ts-node/register ...
).
I could solve it by adding a files
and a ts-node
section to tsconfig.json
like this:
// tsconfig.json
{
"ts-node": {
"files": true
},
"files": [
"src/index.ts",
"src/global.d.ts"
],
"compilerOptions":{
//...
}
}