首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在heroku节点t上编译-- jest类型--找不到类型定义

在heroku节点t上编译-- jest类型--找不到类型定义
EN

Stack Overflow用户
提问于 2022-08-10 10:19:42
回答 1查看 113关注 0票数 0

在heroku上部署时,我正在跟踪错误,并且无法修复它。

在当地工程的基础上做得很好。

错误TS2688:找不到“@ type /jest”的类型定义文件。该文件在程序中是因为:在compilerOptions中指定的类型库‘@ type /jest’的入口点

我的tsconfig文件:

代码语言:javascript
运行
复制
{
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  },
  "compilerOptions": {
    "target": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "module": "commonjs",
    "types": ["jest", "node"],
    "typeRoots": ["./ts-declarations", "node_modules/@types", "./src/types/global"],
    "sourceMap": true,
    "declaration": true,
    "inlineSources": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "strictFunctionTypes": true,
    "skipLibCheck": true,
    "strict": true,
    "outDir": "./dist",
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "baseUrl": ".",
    "forceConsistentCasingInFileNames": true,
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Package.json

代码语言:javascript
运行
复制
  "name": "tasker-server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest --detectOpenHandles --watchAll  --verbose",
    "start": "nodemon -e ts,js --exec ts-node -r tsconfig-paths/register --files ./app.ts",
    "start:prod": "node dist/app",
    "build": "tsc --project tsconfig.build.json && tsc-alias"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/sequelize": "^4.28.14",
    "bcrypt": "^5.0.1",
    "body-parser": "^1.20.0",
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "jsonwebtoken": "^8.5.1",
    "mysql2": "^2.3.3",
    "passport": "^0.6.0",
    "passport-jwt": "^4.0.0",
    "passport-session": "^1.0.2",
    "sequelize": "^6.21.2"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "^28.1.6",
    "@types/jsonwebtoken": "^8.5.8",
    "@types/node": "^18.0.0",
    "@types/passport": "^1.0.9",
    "@types/passport-jwt": "^3.0.6",
    "@types/supertest": "^2.0.12",
    "babel-plugin-module-resolver": "^4.1.0",
    "babel-preset-typescript": "^7.0.0-alpha.19",
    "jest": "^28.1.1",
    "node-mocks-http": "^1.11.0",
    "nodemon": "^2.0.16",
    "supertest": "^6.2.3",
    "ts-jest": "^28.0.5",
    "ts-node": "^10.8.1",
    "tsc-alias": "^1.7.0",
    "tsconfig-paths": "^4.1.0",
    "typescript": "^4.7.4"
  }
}

tsconfig.build只为测试文件添加排除

heroku后构建脚本"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false cd client && yarn install && yarn build && cd .. && cd backend && yarn install && yarn build"

EN

Stack Overflow用户

回答已采纳

发布于 2022-08-10 13:05:53

所有的@types都是devDependencies,就像他们应该做的那样。这意味着,默认情况下,它们在运行时不可用。

问题是您的start脚本正在运行一个开发命令,包括nodemon而不是node,以及运行未编译的TypeScript而不是构建的JavaScript。

看起来您已经有了一个名为start:prod的生产脚本,但这不是一个标准脚本,因此Heroku不知道它是什么。我建议您将该脚本重命名为start,并将现有开发脚本重命名为start:dev

代码语言:javascript
运行
复制
"start:dev": "nodemon -e ts,js --exec ts-node -r tsconfig-paths/register --files ./app.ts",
"start": "node dist/app",

然后提交并重新部署。

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

https://stackoverflow.com/questions/73304538

复制
相关文章

相似问题

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