'Heroku build fails for Typescript/Node server (exit code 2)
I've got a Typescript/Apollo Server project that I'm trying to get deployed to Heroku, and have been running in to issues the last few days.
Originally path aliases weren't compiling, however I think that part is working now. The build error I'm seeing in Heroku isn't very helpful (or I'm overlooking something?). Also building it locally appears to be working, however the Heroku build is failing oddly enough.
Here is what the Heroku logs error looks like:
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=verbose
USE_YARN_CACHE=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
! There is an existing .npmrc file that will not be used. All configurations are read from the .yarnrc.yml file.
https://devcenter.heroku.com/articles/migrating-to-yarn-2
-----> Installing binaries
engines.node (package.json): 16.13.1
engines.npm (package.json): 8.1.2
engines.yarn (package.json): unspecified (use default)
Resolving node version 16.13.1...
Downloading and installing node 16.13.1...
npm verb cli [
npm verb cli '/tmp/build_e000284d/.heroku/node/bin/node',
npm verb cli '/tmp/build_e000284d/.heroku/node/bin/npm',
npm verb cli '--version'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm timing npm:load:whichnode Completed in 0ms
npm timing config:load:defaults Completed in 1ms
npm timing config:load:file:/tmp/build_e000284d/.heroku/node/lib/node_modules/npm/npmrc Completed in 4ms
npm timing config:load:builtin Completed in 4ms
npm timing config:load:cli Completed in 2ms
npm timing config:load:env Completed in 0ms
npm timing config:load:file:/tmp/build_e000284d/.npmrc Completed in 0ms
npm timing config:load:project Completed in 4ms
npm timing config:load:file:/app/.npmrc Completed in 0ms
npm timing config:load:user Completed in 0ms
npm timing config:load:file:/tmp/build_e000284d/.heroku/node/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 0ms
npm timing config:load:credentials Completed in 1ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 13ms
npm timing npm:load:configload Completed in 13ms
npm timing npm:load:setTitle Completed in 0ms
npm timing npm:load:setupLog Completed in 0ms
npm timing config:load:flatten Completed in 2ms
npm timing npm:load:cleanupLog Completed in 1ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load:projectScope Completed in 1ms
npm timing npm:load Completed in 22ms
npm verb exit 0
npm timing npm Completed in 155ms
npm info ok
npm 8.1.2 already installed with node
Resolving yarn version 1.22.x...
Downloading and installing yarn (1.22.18)
Using yarn 3.2.0
npm verb cli [
npm verb cli '/tmp/build_e000284d/.heroku/node/bin/node',
npm verb cli '/tmp/build_e000284d/.heroku/node/bin/npm',
npm verb cli '--version'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm timing npm:load:whichnode Completed in 1ms
npm timing config:load:defaults Completed in 1ms
npm timing config:load:file:/tmp/build_e000284d/.heroku/node/lib/node_modules/npm/npmrc Completed in 0ms
npm timing config:load:builtin Completed in 0ms
npm timing config:load:cli Completed in 2ms
npm timing config:load:env Completed in 0ms
npm timing config:load:file:/tmp/build_e000284d/.npmrc Completed in 1ms
npm timing config:load:project Completed in 4ms
npm timing config:load:file:/app/.npmrc Completed in 0ms
npm timing config:load:user Completed in 0ms
npm timing config:load:file:/tmp/build_e000284d/.heroku/node/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 1ms
npm timing config:load:credentials Completed in 0ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 9ms
npm timing npm:load:configload Completed in 9ms
npm timing npm:load:setTitle Completed in 0ms
npm timing npm:load:setupLog Completed in 1ms
npm timing config:load:flatten Completed in 2ms
npm timing npm:load:cleanupLog Completed in 1ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load:projectScope Completed in 1ms
npm timing npm:load Completed in 19ms
npm verb exit 0
npm timing npm Completed in 138ms
npm info ok
-----> Installing dependencies
Running 'yarn install' with yarn.lock
➤ YN0000: ┌ Resolution step
➤ YN0002: │ @endemolshinegroup/cosmiconfig-typescript-loader@npm:3.0.2 [f6a73] doesn't provide typescript (pfa4cc), requested by ts-node
➤ YN0060: │ my_app_backend@workspace:. provides graphql (p53568) with version 16.3.0, which doesn't satisfy what @graphql-tools/utils requests
➤ YN0060: │ my_app_backend@workspace:. provides graphql (pc6605) with version 16.3.0, which doesn't satisfy what @graphql-codegen/typescript-resolvers and some of its descendants request
➤ YN0060: │ my_app_backend@workspace:. provides graphql (p8b95a) with version 16.3.0, which doesn't satisfy what @graphql-tools/schema requests
➤ YN0060: │ my_app_backend@workspace:. provides graphql (p2f850) with version 16.3.0, which doesn't satisfy what graphql-middleware requests
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 437ms
➤ YN0000: ┌ Link step
➤ YN0007: │ my_app_backend@workspace:. must be built because it never has been before or the last one failed
➤ YN0007: │ core-js@npm:3.6.5 must be built because it never has been before or the last one failed
➤ YN0007: │ bufferutil@npm:4.0.6 must be built because it never has been before or the last one failed
➤ YN0007: │ es5-ext@npm:0.10.59 must be built because it never has been before or the last one failed
➤ YN0007: │ utf-8-validate@npm:5.0.9 must be built because it never has been before or the last one failed
➤ YN0007: │ @apollo/protobufjs@npm:1.2.2 must be built because it never has been before or the last one failed
➤ YN0009: │ my_app_backend@workspace:. couldn't be built successfully (exit code 2, logs can be found here: /tmp/xfs-65bd0355/build.log)
➤ YN0000: └ Completed in 12s 984ms
➤ YN0000: Failed with errors in 13s 844ms
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
package.json
{
"name": "my_app_backend",
"engines": {
"node": "16.13.1",
"npm": "8.1.2"
},
"scripts": {
"dev": "ts-node-dev --no-notify --respawn --transpile-only -r tsconfig-paths/register src/server",
"start": "node dist/server.js",
"clean": "rm -rf dist",
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
"postinstall": "yarn build",
"codegen": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/introspection": "2.1.1",
"@graphql-codegen/typescript": "2.4.7",
"@graphql-codegen/typescript-resolvers": "2.5.4",
"@graphql-tools/schema": "7.1.5",
"@graphql-tools/utils": "7.10.0",
"@supabase/supabase-js": "^1.31.1",
"apollo-server": "^3.6.4",
"bcryptjs": "^2.4.3",
"cloudinary": "^1.28.1",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"graphql": "^16.3.0",
"graphql-middleware": "^6.1.18",
"graphql-scalars": "^1.15.0",
"jsonwebtoken": "^8.5.1",
"ts-node": "10.7.0",
"tsc": "^2.0.4",
"tsc-alias": "^1.6.5",
"tsconfig-paths": "^3.14.0"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "17.0.21",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
"ts-node-dev": "^1.1.8",
"typescript": "4.6.2"
},
"packageManager": "[email protected]"
}
Procfile
web: node server.js
tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "dist",
"skipLibCheck": true,
"lib": [
"esnext"
],
"strict": true,
"module": "commonjs",
"target": "ES6",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
I've been experimenting with moving packages between dependencies
and devDepencies
, which is why you'll maybe see some that are normally in dev moved over to the regular dependencies (since Heroku prunes devDependencies during build).
What might be causing this error? Why does the build work locally but not in Heroku?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|