You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js Express项目服务器报错Cannot find module '@babel/core'求助

Fixing "Cannot find module '@babel/core'" in Node.js Express Deployment

Hey there, let's break down why your app runs fine locally but throws that error on the server, and walk through the fixes:

1. Move @babel/core to Dependencies

Right now, @babel/core is listed under devDependencies—but if your app needs it to run (like when using babel-node to start the server), production environments won't install dev dependencies by default.

Update your package.json to move it to dependencies:

"dependencies": {
  "@babel/cli": "^7.8.4",
  "@babel/core": "^7.9.6", // Add this line here
  "@babel/runtime": "^7.9.6",
  "cookie-parser": "^1.4.5",
  // ... keep all your other dependencies
},
"devDependencies": {
  // Remove "@babel/core": "^7.9.6" from here
  "@babel/node": "^7.8.7",
  "@babel/plugin-transform-runtime": "^7.9.6",
  // ... keep other dev dependencies
}

Then re-install dependencies on your server:

npm install

2. Install Dev Dependencies on the Server

If you need dev dependencies for your deployment workflow (like compiling code on the server instead of locally), install them explicitly:

npm install --include=dev

Also, check if your server has NODE_ENV=production set—npm skips dev dependencies automatically when this variable is set. You can temporarily unset it if needed, but moving @babel/core to dependencies is the cleaner long-term fix.

3. Match Your Server's Start Command to Local

Double-check how you're starting the app locally vs. on the server. If you use babel-node locally (via a script like "dev": "nodemon --exec babel-node app.js"), but run node app.js directly on the server, you'll miss the Babel compilation layer.

Make sure your package.json has a consistent start script:

"scripts": {
  "start": "babel-node app.js",
  "dev": "nodemon --exec babel-node app.js"
}

Then start the app on the server with:

npm start

Quick Cleanup Tip

You've got both old babel-core@6.x and new @babel/core@7.x installed—this can cause version conflicts. Remove the old Babel 6 packages (babel-core, babel-preset-es2015, babel-preset-stage-0) from devDependencies to avoid weird issues down the line.

内容的提问来源于stack exchange,提问作者mohammad pakivand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:17:55