[英]Compile on heroku node ts- jest types- cannot find type definition
error TS2688: Cannot find type definition file for '@types/jest'.
错误 TS2688:找不到“@types/jest”的类型定义文件。 The file is in the program because: Entry point of type library '@types/jest' specified in compilerOptions
该文件在程序中,因为:compilerOptions 中指定的类型库“@types/jest”的入口点
My tsconfig file:我的 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 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 only adds exclude for test files tsconfig.build 只为测试文件添加排除
heroku post build script "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false cd client && yarn install && yarn build && cd.. && cd backend && yarn install && yarn build"
heroku 后构建脚本
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false cd client && yarn install && yarn build && cd.. && cd backend && yarn install && yarn build"
kindly try to change this请尝试改变这一点
"types": ["jest", "node"],
to this对此
"types": [
"jasmine",
"node"
]
All of your @types
are devDependencies
, as they should be.你所有的
@types
都是devDependencies
,因为它们应该是。 That means that, by default, they are not available at runtime .这意味着,默认情况下, 它们在运行时不可用。
The problem is that your start
script is running a development command, including nodemon
instead of node
, and running the uncompiled TypeScript instead of the built JavaScript.问题是您的
start
脚本正在运行开发命令,包括nodemon
而不是node
,并运行未编译的 TypeScript 而不是内置的 JavaScript。
It looks like you already have a production script called start:prod
, but that's not a standard script so Heroku has no idea what it is.看起来您已经有一个名为
start:prod
的生产脚本,但这不是标准脚本,因此 Heroku 不知道它是什么。 I suggest you simply rename that script to start
and rename your existing development script to start:dev
:我建议您只需将该脚本重命名为
start
并将您现有的开发脚本重命名为start:dev
:
"start:dev": "nodemon -e ts,js --exec ts-node -r tsconfig-paths/register --files ./app.ts",
"start": "node dist/app",
Then commit and redeploy.然后提交并重新部署。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.