Expressjs application crashed on railway
sas-partner
PROOP

a year ago

when i build my application locally it runs perfect without any error but when build happens on railway it crashed and the reason is Unexpected token ";" it seems some kind of injection happens to production code

note => i'm using esbuild to build expressjs

here is my configurations of esuild

   import esbuild from 'esbuild'
   import * as packages from './package.json' with { type: 'json' }
   const listPackages = [...Object.keys(packages.default.dependencies)]
  esbuild
   .build({
    entryPoints: ['./src/index.ts'],
    outfile: './build/index.cjs',
    bundle: true,
    platform: 'node',
    target: 'node22', // Adjust based on your Node.js version
    sourcemap: true, // Optional: For easier debugging
    minify: true, // Optional: Set to true for production
    external: ['mock-aws-s3', 'aws-sdk', 'nock', ...listPackages], // Exclude these packages
    packages: 'external',
  })
  .then(() => {
    console.log('Build succeeded')
  })
  .catch(() => {
    process.exit(1)
  })

And there are my npm scripts

"build": "rimraf build && node esbuild.config.mjs",
"start": "cross-env NODE_ENV=production node  build/index.cjs",
"postbuild": "npx prisma generate"
Solved

3 Replies

unicodeveloper
PRO

a year ago

Hi, I just took a look at your error log.

Seems you either have to downgrade the mime dependency to a v3.0.0 that supports commonJS or change your code to use dynamic import like the error log says.

OR

In package.json, add "type": "module" and use ESM imports all through.


Status changed to Awaiting User Response Railway 12 months ago


sas-partner
PROOP

a year ago

I downgraded the mime dependency and it's now working well


Status changed to Awaiting Railway Response Railway 12 months ago


unicodeveloper
PRO

a year ago

Awesome


Status changed to Awaiting User Response Railway 12 months ago


Status changed to Solved unicodeveloper 12 months ago


Loading...