web-infra-dev / rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.
https://rsbuild.dev/
MIT License
1.82k stars 140 forks source link

[Bug]: rs-build 1.1.0 umd externals not working. #3957

Closed guowenfh closed 4 days ago

guowenfh commented 5 days ago

Version

System:
    OS: macOS 14.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 123.58 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 130.0.6723.117
    Safari: 17.1
  npmPackages:
    @rsbuild/core: ^1.1.0 => 1.1.0

Details

import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
import { pluginSass } from "@rsbuild/plugin-sass";
import { pluginUmd } from "@rsbuild/plugin-umd";
export default defineConfig({
  plugins: [pluginSass(), pluginUmd({ name: "Text" }), pluginReact()],
  output: {
    externals: {

      react: "React",
      "react-dom": "ReactDOM",
      "@formily/react-schema-renderer": {
        root: ["Formily", "ReactSchemaRenderer"],
        commonjs: ["Formily", "ReactSchemaRenderer"],
        commonjs2: ["Formily", "ReactSchemaRenderer"],
      },
      "@formily/shared": {
        root: ["Formily", "Shared"],
        commonjs: ["Formily", "Shared"],
        commonjs2: ["Formily", "Shared"],
      },
      "@formily/core": {
        root: ["Formily", "Core"],
        commonjs: ["Formily", "Core"],
        commonjs2: ["Formily", "Core"],
      },
      "@formily/next": {
        root: ["Formily", "Next"],
        commonjs: ["Formily", "Next"],
        commonjs2: ["Formily", "Next"],
      },
      "@formily/react": {
        root: ["Formily", "React"],
        commonjs: ["Formily", "React"],
        commonjs2: ["Formily", "React"],
      },
    },
  },
});
import * as FormilyReact from "@formily/react";

rs-build 1.1.0 not working. Image

but rs-build 1.0.17 is working. Image

Reproduce link

https://codesandbox.io/p/devbox/dx7k6v

Reproduce Steps

1.run 'pnpm i &pnpm dev 2.check the error logs

9aoy commented 4 days ago

amd is required in rspack 1.1.1. Reference https://github.com/web-infra-dev/rspack/pull/8369

chenjiahan commented 4 days ago

You can add amd to fix it and ensure the UMD output is correct:

export default defineConfig({
  output: {
    externals: {
      "@formily/react-schema-renderer": {
        root: ["Formily", "ReactSchemaRenderer"],
        commonjs: ["Formily", "ReactSchemaRenderer"],
        commonjs2: ["Formily", "ReactSchemaRenderer"],
+       amd: ["Formily", "ReactSchemaRenderer"],
      },
    },
  },
});