rspack-contrib / rsbuild-plugin-umd

An Rsbuild plugin to generate outputs in UMD format.
MIT License
2 stars 0 forks source link

Build error after upgrade to 1.0.0 #1

Closed hustcer closed 3 months ago

hustcer commented 3 months ago

rsbuild config:

import { defineConfig } from '@rsbuild/core';
import { pluginUmd } from '@rsbuild/plugin-umd';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginLess } from '@rsbuild/plugin-less';
import { pluginReact } from '@rsbuild/plugin-react';

import { DEFINE } from '../../../env.mjs';

const PKG_NAME = 'abc';
const INDEX_FILE = './view/index.jsx';

export default defineConfig({
  source: {
    define: DEFINE,
    entry: {
      index: INDEX_FILE,
    },
  },
  output: {
    sourceMap: {
      js: 'source-map',
    },
    polyfill: 'usage',
    // 默认情况下,Rsbuild 会把 CSS 提取为独立的 .css 文件,并输出到构建产物目录。
    // 设置该选项为 true 后,CSS 文件会被内联到 JS 文件中,并在运行时通过 <style> 标签插入到页面上
    injectStyles: true,
    cleanDistPath: true,
    distPath: {
      root: './build',
      js: 'view',
      css: 'view',
    },
    filename: {
      js: 'index.js',
    },
  },
  tools: {
    bundlerChain: (chain) => {
      chain.ignoreWarnings([/Using \/ for division outside of calc()/]);
    },
  },
  plugins: [pluginReact(), pluginSass(), pluginLess(), pluginUmd({ name: PKG_NAME })],
});

Works fine with 0.7.10, however, after upgrading to v1.0.0 got the following error:

  Rsbuild v1.0.0

warn    Rsbuild plugin "rsbuild:sass" registered multiple times.
warn    Rsbuild plugin "rsbuild:less" registered multiple times.
error   Failed to build, please check logs.
error   Cannot access Rsbuild config until modifyRsbuildConfig is called.
    at Object.getRsbuildConfig (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+core@1.0.0/node_modules/@rsbuild/core/dist/rspack-provider/core/initPlugins.js:34:13)
    at /Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+plugin-umd@1.0.0_@rsbuild+core@1.0.0/node_modules/@rsbuild/plugin-umd/dist/index.cjs:32:30
    at Object.call (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+shared@1.0.0/node_modules/@rsbuild/shared/dist/createHook.js:32:28)
    at async modifyRsbuildConfig (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+core@1.0.0/node_modules/@rsbuild/core/dist/rspack-provider/core/initConfigs.js:31:22)
    at async initConfigs (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+core@1.0.0/node_modules/@rsbuild/core/dist/rspack-provider/core/initConfigs.js:47:3)
    at async build (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+core@1.0.0/node_modules/@rsbuild/core/dist/rspack-provider/core/build.js:52:31)
    at async Command.<anonymous> (/Users/hustcer/github/terminus/asrm-ui/node_modules/.pnpm/@rsbuild+core@1.0.0/node_modules/@rsbuild/core/dist/cli/commands.js:87:7)
 ELIFECYCLE  Command failed with exit code 1.

rsbuild and plugin versions:

    "@rsbuild/core": "^1.0.0-alpha.5",
    "@rsbuild/plugin-less": "^1.0.0-alpha.5",
    "@rsbuild/plugin-node-polyfill": "^1.0.1",
    "@rsbuild/plugin-react": "^1.0.0-alpha.5",
    "@rsbuild/plugin-sass": "^1.0.0-alpha.5",
    "@rsbuild/plugin-umd": "^1.0.0",
hustcer commented 3 months ago

BTW: Why it told me that:

warn    Rsbuild plugin "rsbuild:sass" registered multiple times.
warn    Rsbuild plugin "rsbuild:less" registered multiple times.

Obviously, I have just registered once.

chenjiahan commented 3 months ago

Hi, you can change "^1.0.0-alpha.5" to "1.0.0-alpha.5"

If we use ^1.0.0-alpha.5, the package manager will resolve to @rsbuild/core@1.0.0, which is a deprecated version.

hustcer commented 3 months ago

Thanks for the quick reply, works now