如何解决找不到带有模块样式声明文件的模块的声明文件
// @types/index.d.ts
import type { Profile } from "passport-discord"
declare module "fastify" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface PassportUser extends Profile {}
}
declare module "@elastic/ecs-pino-format"
// @Todo: remove when https://github.com/pinojs/pino-elasticsearch/issues/54 has been fixed
declare module "pino-elasticsearch"
在我的 tsconfig.json
中,我尝试添加 "include": ["@types","src"],
但运行我的构建命令
"build": "rimraf dist && NODE_ENV=development npm run nexus:reflect && tsc","nexus:reflect": "SHOULD_EXIT_AFTER_GENERATE_ARTIFACTS=true ts-node --transpile-only src/schema.ts",
结果
daniell@DESKTOP-EKQSHNG:~/GitHub/akira$ npm run build
> akira@1.0.0 build
> rimraf dist && NODE_ENV=development npm run nexus:reflect && tsc
> akira@1.0.0 nexus:reflect
> SHOULD_EXIT_AFTER_GENERATE_ARTIFACTS=true ts-node --transpile-only src/schema.ts
Generated Artifacts:
TypeScript Types ==> /home/daniell/GitHub/akira/node_modules/@types/nexus-typegen/index.d.ts
GraphQL Schema ==> (not enabled)
src/utilities/logger.ts:1:23 - error TS7016: Could not find a declaration file for module '@elastic/ecs-pino-format'. '/home/daniell/GitHub/akira/node_modules/@elastic/ecs-pino-format/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/elastic__ecs-pino-format` if it exists or add a new declaration (.d.ts) file containing `declare module '@elastic/ecs-pino-format';`
1 import ecsFormat from "@elastic/ecs-pino-format"
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/utilities/logger.ts:3:25 - error TS7016: Could not find a declaration file for module 'pino-elasticsearch'. '/home/daniell/GitHub/akira/node_modules/pino-elasticsearch/lib.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/pino-elasticsearch` if it exists or add a new declaration (.d.ts) file containing `declare module 'pino-elasticsearch';`
3 import pinoElastic from "pino-elasticsearch"
~~~~~~~~~~~~~~~~~~~~
Found 2 errors.
解决方法
使用带有 files
选项的 ts-node 怎么样?
- "nexus:reflect": "SHOULD_EXIT_AFTER_GENERATE_ARTIFACTS=true ts-node --transpile-only src/schema.ts",+ "nexus:reflect": "SHOULD_EXIT_AFTER_GENERATE_ARTIFACTS=true ts-node --transpile-only --files src/schema.ts",
文档说 ts-node
默认不会在启动时从 files
加载 include
、exclude
和 tsconfig.json
。
https://github.com/TypeStrong/ts-node#help-my-types-are-missing
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。