web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.09k stars 521 forks source link

process is not define when i start the project #2994

Closed AuglyXu closed 1 year ago

AuglyXu commented 1 year ago

System Info

System:mac

Details

image

启动项目后发生的问题,不知道问题具体出现在哪里

Reproduce link

No response

Reproduce Steps

yarn install yarn start

hardfist commented 1 year ago

It seems you may forget to define some process.env.xxx which cause you access process on the browser(which not exits), you can check out the error stack and see how do you use process in your code

hardfist commented 1 year ago

@AuglyXu is your problem solved

AuglyXu commented 1 year ago

I will check tomorrow.Today I took a rough look at my project, but I didn’t find undefined process.env.xxx.If the error still exist,I will try to reproduce in demo project

yxzh614 commented 1 year ago

i have this problem too. image

    "@rspack/cli": "^0.1.9",
    "@rspack/plugin-node-polyfill": "^0.1.9",
hardfist commented 1 year ago

please provide reproducible demo so we can find out the reason

yxzh614 commented 1 year ago

@hardfist demo is here https://github.com/yxzh614/demo_rspack_error

problem is these deps

"@rspack/plugin-node-polyfill": "^0.1.9",
"jmuxer": "^2.0.5",
hardfist commented 1 year ago

@yxzh614 you forget to config define, so process.env.NODE_DEBUG is not transformed

builtins: {
    define: {
      'process.env.NODE_DEBUG': JSON.stringify(false),
    },
    html: [
      {
        template: './index.html',
      },
    ],
  },
AuglyXu commented 1 year ago

@hardfist demo is here https://github.com/AuglyXu/lerna-test problem is the deps "insight-iclient-leaflet"

how can i cover all the process.env.xxx in 3rd party library

hardfist commented 1 year ago

@hardfist demo is here AuglyXu/lerna-test problem is the deps "insight-iclient-leaflet"

how can i cover all the process.env.xxx in 3rd party library

if you find third party ship process.env.xxx, it's normally a bug of the library or the library should document this behavior, bundler can't automatic fix this for you

AuglyXu commented 1 year ago

@hardfist demo is here AuglyXu/lerna-test problem is the deps "insight-iclient-leaflet" how can i cover all the process.env.xxx in 3rd party library

if you find third party ship process.env.xxx, it's normally a bug of the library or the library should document this behavior, bundler can't automatic fix this for you

The dep is forked from @supermap/iclient-leaflet. It is a frequently used library and I can start successfully on webpack.Please can you help me locate what caused the problem in demo and how can i fixed the error?Thanks.

AuglyXu commented 1 year ago

I define the environment and use the demo from @yxzh614 , it occurs another unexpected error and my demo occured too.These errors depend on the third-party library used and are not predictable.

hardfist commented 1 year ago

I define the environment and use the demo from @yxzh614 , it occurs another unexpected error and my demo occured too.These errors depend on the third-party library used and are not predictable.

your demo is not a minimal demo and it seems your application use libraries which use node api, so you need to provide node-polyfill to make it work, after upgrade your @rspack/cli to 0.1.10 and provide node-polyfill by @rspack/plugin-node-polyfill@0.1.9-alpha0, your application is running image

AuglyXu commented 1 year ago

I define the environment and use the demo from @yxzh614 , it occurs another unexpected error and my demo occured too.These errors depend on the third-party library used and are not predictable.

your demo is not a minimal demo and it seems your application use libraries which use node api, so you need to provide node-polyfill to make it work, after upgrade your @rspack/cli to 0.1.10 and provide node-polyfill by @rspack/plugin-node-polyfill@0.1.9-alpha0, your application is running image

Thanks, and the error had fixed

mirageN1349 commented 2 weeks ago

If you are using rsbuild then install https://v0.rsbuild.dev/plugins/list/plugin-node-polyfill It solve problem for me