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
1 Answer
Reset to default 0the problem was with mime package so I downgraded the package to 3.0.0 and the application is now working well