Can't access new Remix app

I have trouble getting my new app to run. It is a remix app with express. Here is my package.json

{
  "private": true,
  "name": "moaclayco",
  "description": "",
  "license": "",
  "scripts": {
    "css": "tailwindcss --output ./app/styles/tailwind.css --config ./tailwind.config.js --watch",
    "dev2": "remix run",
    "postinstall": "remix setup node",
    "start": "remix-serve build",
    "dev": "pm2-dev ./other/pm2.config.js",
    "build:css": "postcss styles/**/*.css --base styles --dir app/styles",
    "build:css:prod": "npm run build:css -- --env production",
    "clean": "rimraf ./node_modules/.cache ./server/dist ./build ./public/build \"./app/styles/**/*.css\"",
    "prebuild": "npm run clean && echo All clean ✨",
    "build:remix": "cross-env NODE_ENV=production remix build",
    "build": "npm run build:css:prod && npm run build:remix"
  },
  "dependencies": {
    "@remix-run/express": "^1.2.3",
    "@remix-run/react": "^1.2.3",
    "@remix-run/serve": "^1.2.3",
    "@stripe/react-stripe-js": "^1.6.0",
    "@stripe/stripe-js": "^1.21.1",
    "compression": "^1.7.4",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "framer-motion": "^5.3.0",
    "mongoose": "^6.0.12",
    "nodemailer": "^6.7.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.0.2",
    "react-router-hash-link": "^2.4.3",
    "react-swipeable": "^6.2.0",
    "react-use-cart": "^1.13.0",
    "remix": "^1.2.3",
    "stripe": "^8.186.1",
    "tailwindcss": "^2.2.19"
  },
  "devDependencies": {
    "@remix-run/dev": "^1.2.3",
    "@tailwindcss/aspect-ratio": "^0.3.0",
    "@tailwindcss/forms": "^0.3.4",
    "@tailwindcss/line-clamp": "^0.2.2",
    "@tailwindcss/typography": "^0.4.1",
    "@types/node": "^16.11.6",
    "@types/nodemailer": "^6.4.4",
    "@types/react": "^17.0.24",
    "@types/react-dom": "^17.0.9",
    "@types/react-router-hash-link": "^2.4.4",
    "@types/stripe": "^8.0.417",
    "autoprefixer": "^10.4.0",
    "cross-env": "^7.0.3",
    "pm2": "^5.1.2",
    "postcss": "^8.3.11",
    "postcss-cli": "^9.0.1",
    "postcss-import": "^14.0.2",
    "prettier": "^2.4.1",
    "prettier-plugin-tailwind": "^2.2.12",
    "rsync": "^0.6.1",
    "typescript": "^4.1.2"
  },
  "engines": {
    "node": ">=14"
  },
  "sideEffects": false
}

And the fly.toml

app = "moaclayco"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "10s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

My index.js

require('@remix-run/node/globals').installGlobals()
const path = require('path')
const express = require('express')
const {createRequestHandler} = require('@remix-run/express')
const compression = require('compression')
const connector = require('./connector')
connector()

const MODE = process.env.NODE_ENV
const BUILD_DIR = path.join(process.cwd(), 'build')
let app = express()

app.use(compression())
app.use(express.static('public', {maxAge: '1w'}))

app.use(express.static('public/fonts', {immutable: true, maxAge: '1y'}))
app.use(express.static('public/images', {immutable: true, maxAge: '1y'}))
app.use(express.static('public/build', {immutable: true, maxAge: '1y'}))

app.all(
  '*',
  MODE === 'production'
    ? createRequestHandler({build: require(BUILD_DIR)})
    : (req, res, next) => {
        purgeRequireCache()
        const build = require(BUILD_DIR)
        return createRequestHandler({build, mode: MODE})(req, res, next)
      },
)

const port = process.env.PORT ?? 3000
app.listen(port, () => {
  require(BUILD_DIR)
  console.log(`Express server listening on port ${port}`)
})

function purgeRequireCache() {
  for (const key in require.cache) {
    if (key.startsWith(BUILD_DIR)) {
      delete require.cache[key]
    }
  }
}

All secrets are set but in the log I’m getting this.

2022-03-01T15:46:36Z runner[51adcb49] fra [info]Unpacking image
2022-03-01T15:46:40Z runner[51adcb49] fra [info]Preparing kernel init
2022-03-01T15:46:41Z runner[51adcb49] fra [info]Configuring firecracker
2022-03-01T15:46:41Z runner[51adcb49] fra [info]Starting virtual machine
2022-03-01T15:46:41Z app[51adcb49] fra [info]Starting init (commit: 0c50bff)...
2022-03-01T15:46:41Z app[51adcb49] fra [info]Preparing to run: `docker-entrypoint.sh npm run start` as root
2022-03-01T15:46:41Z app[51adcb49] fra [info]2022/03/01 15:46:41 listening on [fdaa:0:3d01:a7b:23c4:51ad:cb49:2]:22 (DNS: [fdaa::3]:53)
2022-03-01T15:46:42Z app[51adcb49] fra [info]> start
2022-03-01T15:46:42Z app[51adcb49] fra [info]> remix-serve build
2022-03-01T15:46:42Z app[51adcb49] fra [info](node:532) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
2022-03-01T15:46:42Z app[51adcb49] fra [info](Use `node --trace-warnings ...` to show where the warning was created)
2022-03-01T15:46:42Z app[51adcb49] fra [info]Remix App Server started at http://172.19.2.58:3000
2022-03-01T15:47:10Z runner[55aeb663] cdg [info]Shutting down virtual machine
2022-03-01T15:47:10Z app[55aeb663] cdg [info]Sending signal SIGINT to main child process w/ PID 515
2022-03-01T15:52:58Z app[51adcb49] fra [info]GET / - - - - ms

fra [warn]error.code=2004 request.method=“GET” request.url=“https://moaclayco.fly.dev/” request.id=“01FX34J65QTKZHGQP49A97WV5R-fra” response.status=502

Hello!
These errors (the error.code 2004 and the response.status 502) are application connection idle errors, meaning that there was no read or write response for 60s, so we closed it.
Can you check that there is nothing preventing your app form fully accepting or responding to a request?

Thanks @zee I had an bug in my start script but getting a lot of other errors

“start”: “cross-env NODE_ENV=production node ./build/index.js”

TIMESTAMP               TYPE            MESSAGE                         
2022-03-01T17:18:12Z    Received        Task received by client        
2022-03-01T17:18:12Z    Task Setup      Building Task Directory        
2022-03-01T17:19:30Z    Started         Task started by client         
2022-03-01T17:19:36Z    Terminated      Exit Code: 0                   
2022-03-01T17:19:36Z    Restarting      Task restarting in 1.100123248s
2022-03-01T17:19:51Z    Started         Task started by client         
2022-03-01T17:20:01Z    Terminated      Exit Code: 0                   
2022-03-01T17:20:01Z    Restarting      Task restarting in 1.206464925s
2022-03-01T17:20:30Z    Started         Task started by client         

2022-03-01T17:19:59Z   [info](node:537) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
2022-03-01T17:19:59Z   [info](Use `node --trace-warnings ...` to show where the warning was created)
2022-03-01T17:19:59Z   [info]npm notice
2022-03-01T17:19:59Z   [info]npm notice New minor version of npm available! 8.1.2 -> 8.5.2
2022-03-01T17:19:59Z   [info]npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.2>
2022-03-01T17:19:59Z   [info]npm notice Run `npm install -g npm@8.5.2` to update!
2022-03-01T17:19:59Z   [info]npm notice
2022-03-01T17:19:59Z   [info]Main child exited normally with code: 0
2022-03-01T17:19:59Z   [info]Starting clean up.
2022-03-01T17:20:06Z   [info]Starting instance
2022-03-01T17:20:06Z   [info]Configuring virtual machine
2022-03-01T17:20:06Z   [info]Pulling container image
2022-03-01T17:20:08Z   [info]Unpacking image
2022-03-01T17:20:08Z   [info]Preparing kernel init
2022-03-01T17:20:29Z   [info]Configuring firecracker
2022-03-01T17:20:29Z   [info]Starting virtual machine
2022-03-01T17:20:30Z   [info]Starting init (commit: 0c50bff)...
2022-03-01T17:20:30Z   [info]Preparing to run: `docker-entrypoint.sh npm run start` as root
2022-03-01T17:20:30Z   [info]2022/03/01 17:20:30 listening on [fdaa:0:3d01:a7b:abc:13c6:a05b:2]:22 (DNS: [fdaa::3]:53)
2022-03-01T17:20:32Z   [info]> start
2022-03-01T17:20:32Z   [info]> cross-env NODE_ENV=production node ./build/index.js
2022-03-01T17:20:35Z   [info](node:537) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
2022-03-01T17:20:35Z   [info](Use `node --trace-warnings ...` to show where the warning was created)
2022-03-01T17:20:35Z   [info]npm notice
2022-03-01T17:20:35Z   [info]npm notice New minor version of npm available! 8.1.2 -> 8.5.2
2022-03-01T17:20:35Z   [info]npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.2>
2022-03-01T17:20:35Z   [info]npm notice Run `npm install -g npm@8.5.2` to update!
2022-03-01T17:20:35Z   [info]npm notice
2022-03-01T17:20:36Z   [info]Main child exited normally with code: 0
2022-03-01T17:20:36Z   [info]Starting clean up.
--> v8 failed - Failed due to unhealthy allocations - not rolling back to stable job version 8 as current job has same specification and deploying as v9 

Failed due to unhealthy allocations

I deleted the app and tried again.

Release v1 created
Monitoring Deployment

1 desired, 1 placed, 0 healthy, 1 unhealthy
v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to
***v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v2 

Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

Could you check your logs with fly logs this may give you more information on what is causing the app to fail health checks.

Instance
ID PROCESS VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
6c5df929 4 fra run running 1 total 2 43s ago

Recent Events
TIMESTAMP TYPE MESSAGE
2022-03-01T18:30:04Z Received Task received by client
2022-03-01T18:30:04Z Task Setup Building Task Directory
2022-03-01T18:30:22Z Started Task started by client
2022-03-01T18:30:26Z Terminated Exit Code: 0
2022-03-01T18:30:26Z Restarting Task restarting in 1.182357349s
2022-03-01T18:30:33Z Started Task started by client
2022-03-01T18:30:37Z Terminated Exit Code: 0
2022-03-01T18:30:37Z Restarting Task restarting in 1.01305023s
2022-03-01T18:30:44Z Started Task started by client

2022-03-01T18:30:32Z [info]Pulling container image
2022-03-01T18:30:32Z [info]Unpacking image
2022-03-01T18:30:32Z [info]Preparing kernel init
2022-03-01T18:30:33Z [info]Configuring firecracker
2022-03-01T18:30:33Z [info]Starting virtual machine
2022-03-01T18:30:33Z [info]Starting init (commit: 0c50bff)…
2022-03-01T18:30:33Z [info]Preparing to run: docker-entrypoint.sh npm run start as root
2022-03-01T18:30:33Z [info]2022/03/01 18:30:33 listening on [fdaa:0:3d01:a7b:23c3:6c5d:f929:2]:22 (DNS: [fdaa::3]:53)
2022-03-01T18:30:34Z [info]> start
2022-03-01T18:30:34Z [info]> cross-env NODE_ENV=production node ./build/index.js
2022-03-01T18:30:35Z info ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
2022-03-01T18:30:35Z [info](Use node --trace-warnings ... to show where the warning was created)
2022-03-01T18:30:35Z [info]Main child exited normally with code: 0
2022-03-01T18:30:35Z [info]Starting clean up.
2022-03-01T18:30:42Z [info]Starting instance
2022-03-01T18:30:42Z [info]Configuring virtual machine
2022-03-01T18:30:42Z [info]Pulling container image
2022-03-01T18:30:43Z [info]Unpacking image
2022-03-01T18:30:43Z [info]Preparing kernel init
2022-03-01T18:30:44Z [info]Configuring firecracker
2022-03-01T18:30:44Z [info]Starting virtual machine
2022-03-01T18:30:44Z [info]Starting init (commit: 0c50bff)…
2022-03-01T18:30:44Z [info]Preparing to run: docker-entrypoint.sh npm run start as root
2022-03-01T18:30:44Z [info]2022/03/01 18:30:44 listening on [fdaa:0:3d01:a7b:23c3:6c5d:f929:2]:22 (DNS: [fdaa::3]:53)
2022-03-01T18:30:45Z [info]> start
2022-03-01T18:30:45Z [info]> cross-env NODE_ENV=production node ./build/index.js
2022-03-01T18:30:46Z info ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
2022-03-01T18:30:46Z [info](Use node --trace-warnings ... to show where the warning was created)
2022-03-01T18:30:47Z [info]Main child exited normally with code: 0
2022-03-01T18:30:47Z [info]Starting clean up.
→ v4 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v5

→ Troubleshooting guide at Troubleshooting your Deployment
Error abort

Are you able to run this locally?

Yes, no problem. I have deployed it to vercel before but want to switch

In fact it’s running now https://moaclayco.com but I want to move to fly

@zee Thank you for your time. The setup was wrong in package.json. It should not have pointed to /build but to index.js.

2 Likes

You’re very welcome, glad we could get it worked out!

1 Like