Reputation: 5958
I can't figure out why TypeScript isn't compiling anything that's inside the node_modules
folder.
Here is my tsconfig.json
:
{
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"paths": {
"shared": ["./src/shared"],
"client": ["./src/client"],
"server": ["./src/server"],
"express": ["./node_modules/express"]
},
"plugins": [
{"transform": "ts-transformer-imports"}
],
"esModuleInterop": true,
"allowJs": true,
"target": "es2015",
"module": "commonjs",
"outDir": "./build"
},
"files": ["./src/server/app.ts"]
}
Inside src/server/app.ts
I import both express
and shared
:
import shared from 'shared';
import express from 'express';
The compilation succeeds, and compiled code for shared
and server
are generated. But, for some reason, the code for express
isn't generated!?
This makes absolutely no sense to me... does it randomly decide to not compile something just because it's in a folder called node_modules
?
How can I fix this?
Edit: I also tried changing it to "express/*": ["./node_modules/express/*"]
in the config file, which didn't make any difference. (I don't know why it would, but I found that somewhere on the internet)
Upvotes: 1
Views: 3883
Reputation: 1317
Why do you want to compile a package from node_modules? E.g. ./node_modules/express does NOT contains any TS files. NPM packages usually comes with pre-built (or pre-polyfilled) JS code that you have to just import and use. If you have trouble importing e.g. something from Express be sure that you've installed the typings (@types/express) as well
Upvotes: 1