Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

node.js - 找不到具有类型的模块的声明文件(Could not find a declaration file for module that has types)

I am trying to use nodejs package called moment-timezone .

(我正在尝试使用称为moment-timezone nodejs包。)

It has well defined types.

(它具有定义明确的类型。)

It also works well when I try to run the root index file using the command ts-node --files ./src/index.ts .

(当我尝试使用ts-node --files ./src/index.ts命令运行根索引文件时,它也很好用。)

But When I try to run another file that is present in ./src/test/reminder/src using command ts-node --files ./src/test/reminder/src/index.ts , I get this error error TS7016: Could not find a declaration file for module 'moment-timezone'. '/app/node_modules/moment-timezone/index.js' implicitly has an 'any' type.

(但是当我尝试使用ts-node --files ./src/test/reminder/src/index.ts命令运行./src/test/reminder/src存在的另一个文件时,出现此错误error TS7016: Could not find a declaration file for module 'moment-timezone'. '/app/node_modules/moment-timezone/index.js' implicitly has an 'any' type.) error TS7016: Could not find a declaration file for module 'moment-timezone'. '/app/node_modules/moment-timezone/index.js' implicitly has an 'any' type. .

(。)

This index.ts calls a function which in turn calls moment-timezone .

(此index.ts调用一个函数,该函数依次调用moment-timezone 。)

Following is my project structure:

(以下是我的项目结构:)

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

Following is my 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"
    }
  ]
}

The only question is Why is it throwing error when types are present and it is running perfectly for root index.ts?

(唯一的问题是, 为什么在存在类型并且对于根index.ts完美运行时会引发错误?)

I might be missing some important configuration here.

(我这里可能缺少一些重要的配置。)

Can you please help me here.

(你能在这里帮我吗?)

  ask by user3605527 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...