找不到具有类型的模块的声明文件

时间:2019-12-01 09:42:18

标签: node.js typescript types tsconfig ts-node

我正在尝试使用名为moment-timezone的nodejs软件包。它具有定义明确的类型。当我尝试使用命令ts-node --files ./src/index.ts运行根索引文件时,它也很好用。但是,当我尝试使用命令./src/test/reminder/src运行ts-node --files ./src/test/reminder/src/index.ts中存在的另一个文件时,出现此错误

error TS7016: Could not find a declaration file for module 'moment-timezone'. '/app/node_modules/moment-timezone/index.js' implicitly has an 'any' type.

此index.ts调用一个函数,该函数依次调用moment-timezone。以下是我的项目结构:

-node_modules/
-packages/
--api/
---node_modules/
---src/
----test/
-----reminder/
------src/
-------index.ts
---index.ts
--package.json
--tsconfig.json

以下是我的tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": false,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": false,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noEmit": true,
    "typeRoots": [
      "node_modules/@types",
      "./types",
      "../../node_modules/@types"
    ]
  },
  "include": [
    "src",
    "types"
  ],
  "references": [
    {
      "path": "../some-package"
    }
  ]
}

唯一的问题是为什么在存在类型并且对于根index.ts而言它运行完美时会引发错误?我这里可能缺少一些重要的配置。你能在这里帮我吗?

0 个答案:

没有答案