在heroku上部署时,我正在跟踪错误,并且无法修复它。
在当地工程的基础上做得很好。
错误TS2688:找不到“@ type /jest”的类型定义文件。该文件在程序中是因为:在compilerOptions中指定的类型库‘@ type /jest’的入口点
我的tsconfig文件:
{
"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
"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"
发布于 2022-08-10 13:05:53
所有的@types
都是devDependencies
,就像他们应该做的那样。这意味着,默认情况下,它们在运行时不可用。。
问题是您的start
脚本正在运行一个开发命令,包括nodemon
而不是node
,以及运行未编译的TypeScript而不是构建的JavaScript。
看起来您已经有了一个名为start:prod
的生产脚本,但这不是一个标准脚本,因此Heroku不知道它是什么。我建议您将该脚本重命名为start
,并将现有开发脚本重命名为start:dev
。
"start:dev": "nodemon -e ts,js --exec ts-node -r tsconfig-paths/register --files ./app.ts",
"start": "node dist/app",
然后提交并重新部署。
https://stackoverflow.com/questions/73304538
复制相似问题