简体   繁体   中英

How to get VS Code intellisense to search multiple node_modules folders for typescript

I have a node/typescript project structured like so:

- node_modules // => these are loaded npm/package.json
- src
  - node_modules // => shared modules for my project, not on npm
    - lib.ts
  - app.ts
- package.json

I have a secondary node_modules folder for my private packages mainly so I can import them from anywhere in my project and not have to worry about relative paths (as suggested here ) on imports.

This works great because instead of import * as lib from '../../lib' or var lib = require('../../lib') , I can import * as lib from 'lib' .

Typescript compiles/loads lib w/o problem, but VS Code intellisense complains that it "cannot find module 'lib'".

FWIW, here is my tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "module": "commonjs",
    "target": "es2015",
    "rootDir": "src"
  }
}

I needed to modify the package.json of my lib to include a "typings" property:

{
  "name": "lib",
  "version": "0.0.1",
  "main": "lib.js",
  "typings": "lib"
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM