首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决以下类型记录错误:“无法找到命名空间'fastify'"?

如何解决以下类型记录错误:“无法找到命名空间'fastify'"?
EN

Stack Overflow用户
提问于 2020-08-29 12:57:29
回答 1查看 2.6K关注 0票数 2

最近,我决定升级我的所有包在我的法西斯服务器模板。

我的package.json看起来是这样的:

代码语言:javascript
复制
{
    "name": "backend-template",
    "version": "1.0.0",
    "description": "",
    "author": "",
    "license": "ISC",
    "main": "server.ts",
    "scripts": {
        "build": "tsc",
        "test": "jest",
        "start": "node dist/server.js",
        "dev": "cross-env NODE_PATH=src nodemon",
        "lint": "eslint src --ext .js,.ts --max-warnings 0"
    },
    "dependencies": {
        "@types/pg": "^7.14.4",
        "apollo-server-fastify": "^2.17.0",
        "app-module-path": "^2.2.0",
        "axios": "^0.20.0",
        "bcrypt": "^5.0.0",
        "bytebuffer": "^5.0.1",
        "cls-hooked": "^4.2.2",
        "cls-proxify": "^1.0.1",
        "dataloader": "^2.0.0",
        "dotenv": "^8.2.0",
        "fastify": "^3.3.0",
        "fastify-compress": "^3.3.0",
        "fastify-cors": "^4.1.0",
        "fastify-file-upload": "^3.0.0",
        "fastify-gql": "^5.4.0",
        "fastify-helmet": "^5.0.1",
        "fastify-multipart": "^3.1.0",
        "fastify-plugin": "^2.3.3",
        "fastify-swagger": "^3.3.0",
        "fluent-schema": "^1.0.4",
        "graphql": "^15.3.0",
        "graphql-type-datetime": "^0.2.4",
        "graphql-upload": "^11.0.0",
        "httperrors": "^2.3.0",
        "jsonwebtoken": "^8.5.1",
        "jwks-rsa": "^1.9.0",
        "lodash": "^4.17.20",
        "monotonic-id": "^1.1.0",
        "mysql": "^2.18.1",
        "mysql2": "^2.1.0",
        "node-cache": "^5.1.2",
        "pino": "^6.5.1",
        "pino-pretty": "^4.2.0",
        "sequelize": "^6.3.4",
        "stream-buffers": "^3.0.2",
        "stream-to-blob": "^2.0.1",
        "uuid": "^8.3.0",
        "uuid-parse": "^1.1.0",
        "validator": "^13.1.1"
    },
    "devDependencies": {
        "@types/axios": "^0.14.0",
        "@types/jest": "^26.0.10",
        "@types/validatorjs": "^3.15.0",
        "@typescript-eslint/eslint-plugin": "^3.10.1",
        "cross-env": "^7.0.2",
        "eslint": "^7.7.0",
        "eslint-config-airbnb-typescript": "^9.0.0",
        "eslint-plugin-import": "^2.22.0",
        "eslint-plugin-jest": "^23.20.0",
        "eslint-plugin-prettier": "^3.1.4",
        "husky": "^4.2.5",
        "jest": "^26.4.2",
        "lint-staged": "^10.2.13",
        "nodemon": "^2.0.4",
        "prettier": "^2.1.1",
        "ts-jest": "^26.3.0",
        "ts-node": "^9.0.0",
        "typescript": "^4.0.2"
    },
    "lint-staged": {
        "src/**/!(*test).{js,ts,json}": [
            "prettier --write",
            "eslint --max-warnings 0",
            "git add"
        ]
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    }
}

ts.config:

代码语言:javascript
复制
{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": "src",
    "resolveJsonModule": true
  },
  "lib": ["es2015"],
  "include": ["src"]

}

但是当我运行npm run dev

我收到以下错误:

代码语言:javascript
复制
node_modules\ts-node\src\index.ts:500
    return new TSError(diagnosticText, diagnosticCodes)

TSError:⨯无法编译TypeScript: src/app.ts:44:6 -错误TS2503:无法找到命名空间“fastify”。

44 } as fastify.ServerOptionsAsHttp);~ src/app.ts:83:38 -错误TS2503:无法找到命名空间'fastify‘。

83 (请求):CreateClsProxyFastify> => ~ src/app.ts:83:62 -错误TS2503:无法找到命名空间'fastify‘。

83 (请求):CreateClsProxyFastify> =>

节点版本:

代码语言:javascript
复制
v14.9.0

我能做什么?

EN

回答 1

Stack Overflow用户

发布于 2020-09-21 10:36:04

我遇到了同样的问题,对我来说,这是通过显式导入类型来解决的。

即代替

代码语言:javascript
复制
import fastify from 'fastify';

我用过

代码语言:javascript
复制
import { FastifyReply } from 'fastify';

我还使用了FastifyReply而不是FastifyReply<http.ServerResponse>,因为http.ServerResponse已经是默认的了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63647206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档