tsconfig.json typeroots custom path not picked up

怎甘沉沦 提交于 2021-02-18 20:59:40

问题


I have some custom .d.ts files and I want tsc to pick up these files when compiling. In order to get this done I modify the tsconfig.file to include the following

"typeRoots": [
      "../node_modules/@types",
      "./app/modules"
    ]

./app/modules is where my custom .d.ts file resides. Inside the ./app/modules folder I have the following file myModule.d.ts

export declare module myModule {
  function Login();
  function Logout();
}

Now inside my other typescript file I have the following import

import { myModule } from 'myModule';

Here I get the following error Cannot find module 'myModule'.


回答1:


I found the config that fixes this. Note the paths and baseUrl properties:

{
  "version": "2.1.5",
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES5",
    "removeComments": true,
    "preserveConstEnums": true,
    "inlineSourceMap": true,
    "lib": ["es6", "dom"],
    "typeRoots": ["src/subfolder/node_modules/@types"],
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "*": ["src/subfolder/node_modules/@types/*", "*"]
    }
  },
  "exclude": ["node_modules", "src/subfolder/node_modules"]
}


来源:https://stackoverflow.com/questions/41272378/tsconfig-json-typeroots-custom-path-not-picked-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!