web-infra-dev / rsbuild

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

[Bug]: You may need an additional plugin to handle "node:" URIs. #3567

Closed RoyRao2333 closed 1 month ago

RoyRao2333 commented 1 month ago

Version

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.29 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Safari: 17.5
  npmPackages:
    @rsbuild/core: 1.0.1 => 1.0.1
    @rsbuild/plugin-less: 1.0.1 => 1.0.1
    @rsbuild/plugin-react: 1.0.1 => 1.0.1
    @rsbuild/plugin-svgr: 1.0.1 => 1.0.1

Details

// rsbuild.config.ts

import { defineConfig } from '@rsbuild/core';
import { pluginLess } from '@rsbuild/plugin-less';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSvgr } from '@rsbuild/plugin-svgr';

export default defineConfig({
  plugins: [pluginReact(), pluginSvgr(), pluginLess()],
  tools: {
    rspack: {
      node: {
        global: true,
      },
    },
  },
});
// App.tsx

import process from 'node:process';

console.log(process.env.DEV);

I get error:

image

Reproduce link

See codes above

Reproduce Steps

See codes above

SoonIter commented 1 month ago

API from node cannot be used in the browser environment

RoyRao2333 commented 1 month ago

@SoonIter

If so, what's the point of turning on polyfills for Node?

chenjiahan commented 1 month ago

Try this plugin: https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill