Is there any way to get typescript imports working if your node_modules are not located in direct tree?
How can I make Typescript not complain when importing something like rxjs from external/node_modules.
Example:
tree
|-- external
| `-- package.json
|-- index.ts
`-- tsconfig.json
cat tsconfig.json
{
"compilerOptions": {
"module": "amd",
"target": "es5",
"sourceMap": true,
"removeComments": true,
"allowJs": false,
"pretty": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"lib": [ "es2015", "dom" ]
}
}
cat external/package.json
{
"name": "external",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"rxjs": "^5.0.3"
}
}
cat index.ts
import { Observable } from 'rxjs/Rx';
Observable
cd external
yarn install
yarn add v0.18.1
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ [email protected]
└─ [email protected]
✨ Done in 1.39s.
tsc -v
Version 2.1.4
tsc
1 import { Observable } from 'rxjs/Rx';
~~~~~~~~~
../index.ts(1,28): error TS2307: Cannot find module 'rxjs/Rx'.