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"3 Replies
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 • about 1 year ago
a year ago
I downgraded the mime dependency and it's now working well
Status changed to Awaiting Railway Response Railway • about 1 year ago
a year ago
Awesome
Status changed to Awaiting User Response Railway • about 1 year ago
Status changed to Solved unicodeveloper • about 1 year ago
