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

NodeJS 8项目执行npm start命令报错求助(Babel兼容问题)

Fixing "Plugin/Preset files are not allowed to export objects, only functions" with babel-preset-es2015

Hey there, I’ve run into this exact issue before—let’s break down what’s going on and get your server up and running again.

Why This Error Happens

The root problem is a version mismatch between Babel 6 and Babel 7. The babel-preset-es2015 package is a legacy preset for Babel 6, but if your project has accidentally installed Babel 7 core packages (like @babel/core), they won’t play nice together. Babel 7 requires presets/plugins to export functions, while the old es2015 preset exports an object—hence the error you’re seeing.

Step-by-Step Fix

  1. Uninstall the legacy preset and install Babel 7-compatible tools
    First, get rid of the outdated preset, then install the modern replacement (@babel/preset-env which replaces es2015 and is way more flexible) and updated Babelify:

    npm uninstall babel-preset-es2015
    npm install --save-dev @babel/core @babel/preset-env babelify@latest
    
  2. Update your Babel configuration
    You’ll need to update your .babelrc file (or the babel field in package.json) to use the new preset instead of es2015:

    • If using .babelrc:
      {
        "presets": ["@babel/preset-env"]
      }
      
    • If using package.json, add or modify this section:
      "babel": {
        "presets": ["@babel/preset-env"]
      }
      
  3. Verify your build-js script
    Make sure your build-js script in package.json is using the updated babelify. For example, if your script looks like this:

    "scripts": {
      "build-js": "browserify src/client/js/index.js -t babelify -o dist/bundle.js"
    }
    

    It should work with the new setup—no extra flags needed unless you have specific targets to configure.

  4. Clean up and reinstall dependencies (if needed)
    If you still run into issues, clear out old modules and lock files to resolve any hidden conflicts:

    rm -rf node_modules package-lock.json
    npm install
    

Bonus Note

@babel/preset-env is a better choice than babel-preset-es2015 anyway—it automatically transpiles only the features your target environment (like Node.js 8) doesn’t support, which keeps your bundle smaller and faster.

内容的提问来源于stack exchange,提问作者Daniel Pertuz Orozco

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 07:42:06