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

Webpack打包时ES6编写的npm包未被正确打包问题求助

Fixing Webpack 3 Build Error with ES6 npm Package @ui/base

Alright, let's break down why you're hitting this build error and walk through the fixes step by step.

The Root Cause

Webpack 3 doesn't natively transpile ES6+ syntax from node_modules by default — it assumes packages there are already compiled to ES5. Your @ui/base package seems to have either:

  • A misconfigured entry point (its package.json's main field isn't pointing to the correct build file at ui/base/target/package/@ui/base/0/Main.js), or
  • Its build output is still in ES6, which Webpack 3 can't process without Babel.

Solution 1: Force Babel to Transpile @ui/base

Update your Webpack config to tell babel-loader to process this specific package (since Webpack normally skips node_modules).

Modify your webpack.config.js's module.rules section:

module.exports = {
  // ... other config
  module: {
    rules: [
      {
        test: /\.js$/,
        // Exclude all node_modules EXCEPT @ui/base
        exclude: /node_modules(?!\/@ui\/base)/,
        loader: 'babel-loader',
        options: {
          // Use the preset your project already uses (es2015 or env)
          presets: ['es2015']
        }
      }
    ]
  }
};

Make sure you have the necessary Babel dependencies installed for Webpack 3:

npm install babel-loader@7 babel-core babel-preset-es2015 --save-dev

(Note: Webpack 3 works best with babel-loader@7; newer versions require Webpack 4+.)

Solution 2: Fix the Package Entry Point

If the issue is that @ui/base's package.json doesn't point to the correct build file (Main.js), you can override its entry in Webpack with an alias:

Add this to your webpack.config.js:

const path = require('path');

module.exports = {
  // ... other config
  resolve: {
    alias: {
      '@ui/base': path.resolve(
        __dirname,
        'node_modules/@ui/base/target/package/@ui/base/0/Main.js'
      )
    }
  }
};

This ensures your import '@ui/base'; statement directly references the correct built file instead of relying on the package's default entry.

Solution 3: Verify the Package's Build Status

If neither of the above works, double-check that the @ui/base package was actually built correctly. Sometimes build scripts fail silently, leaving uncompiled ES6 source code instead of the expected Main.js. You can manually check the file at node_modules/@ui/base/target/package/@ui/base/0/Main.js to confirm it's ES5-compatible.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:20:00