I'm getting following error while deploying on heroku, and I'm unable to fix it.
Build on local works fine.
error TS2688: Cannot find type definition file for '@types/jest'. The file is in the program because: Entry point of type library '@types/jest' specified in compilerOptions
My tsconfig file:
{
"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 only adds exclude for test files
heroku post build script
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false cd client && yarn install && yarn build && cd .. && cd backend && yarn install && yarn build"
CodePudding user response:
kindly try to change this
"types": ["jest", "node"],
to this
"types": [
"jasmine",
"node"
]
CodePudding user response:
All of your @types
are devDependencies
, as they should be. 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.
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. I suggest you simply rename that script to start
and rename your existing development script to 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.