模块导入忽略package.json中的主字段

时间:2018-11-15 09:15:53

标签: angular typescript

我有一个导入模块的文件(在本例中为react-intercom),此模块中有一个package.json文件,其主字段指向stl_02a

但是,在使用导入时

lib/index.js

打字稿将忽略主字段,而是查找import { IntercomAPI } from 'react-intercom'

在这种情况下,该应用程序是一个带有嵌入式React实例的角度应用程序

这是我们的tsconfig文件

react-intercom/index

和我们的tsconfig.app文件

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/app/*"],
      "#/*": ["src/*"]
    },
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "typeRoots": ["node_modules/@types", "./src/typings.d.ts"],
    "lib": ["es2018", "dom"],
    "allowJs": true,
  },
  "exclude": ["test.ts", "**/*.spec.ts", "node_modules", "build", "dist"],
  "include": ["./src/*.ts", "./src/**/*.ts"],
  "files": ["node_modules/ngx-i18next/index.ts"]
}

1 个答案:

答案 0 :(得分:0)

Finaly找出了问题所在,这与模块有关,而不是我们的配置

结果是one of the last commit added an index.d.ts file at the base of the module,它看起来像打字稿在检查package.json中的main条目之前先检查给定路径中的索引文件

因此它从寻找react-intercom / lib / index.js变成了react-intercom / index.d.ts,它是文件missing the typings for IntercomAPI

相关问题