简体   繁体   English

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

[英]Compile on heroku node ts- jest types- cannot find type definition


I'm getting following error while deploying on heroku, and I'm unable to fix it. 在 heroku 上部署时出现以下错误,我无法修复它。
Build on local works fine. 建立在本地作品上。

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.

相关问题 TS2688:找不到安装了@ types / node的“ node”的类型定义文件 - TS2688: Cannot find type definition file for 'node' with @types/node installed 在打字稿节点项目中使用 monorepo 样式测试目录时,ts-jest 找不到类型信息 - ts-jest cannot find type information when using monorepo style tests directory in a typescript node project Elastic Beanstalk“错误 TS2688:找不到‘节点’的类型定义文件。” - Elastic Beanstalk "error TS2688: Cannot find type definition file for 'node'." ts-node 找不到我的类型定义文件 - ts-node can't find my type definition files “找不到‘async’的类型定义文件。TS2688” - "Cannot find type definition file for 'async'. TS2688" 找不到“节点”的类型定义文件 - Cannot find type definition file for 'node' 构建:找不到“节点”的类型定义文件 - Build:Cannot find type definition file for 'node' ../node_modules/ng2-ckeditor/ckbutton 中的错误。 指令.d.TS:1:23 - 错误 TS2688:找不到“ckeditor”的类型定义文件 - ERROR in ../node_modules/ng2-ckeditor/ckbutton. directive.d.TS: 1:23 - error TS2688: Cannot find type definition file for 'ckeditor' jest/ts/tests 找不到名字“x” - jest/ts/ tests Cannot find name 'x' npm install => 找不到“节点”的类型定义文件 - npm install => Cannot find type definition file for 'node'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM