最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Expressjs application crashed on railway - Stack Overflow

programmeradmin6浏览0评论

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"

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"
Share Improve this question asked Feb 17 at 9:52 Ahmed AbdelrahmanAhmed Abdelrahman 1432 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

the problem was with mime package so I downgraded the package to 3.0.0 and the application is now working well

发布评论

评论列表(0)

  1. 暂无评论