question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

yarn 3 + yarn workspace + webpack 5 + ProviderPlugin doesn't work well

See original GitHub issue

Bug report

What is the current behavior? The build fails with the following messages,

ERROR in ../../.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/lib/defaults/index.js 24:20-27
Module not found: Error: Can't resolve 'process/browser' in '/Users/asdf/Documents/GitHub/yarn2-webpack5-sandbox/.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/lib/defaults'
resolve 'process/browser' in '/Users/asdf/Documents/GitHub/yarn2-webpack5-sandbox/.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/lib/defaults'
  Parsed request is a module
  using description file: /Users/asdf/Documents/GitHub/yarn2-webpack5-sandbox/.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/package.json (relative path: ./lib/defaults)
    resolve as module
      request is not managed by the pnpapi
        axios tried to access process. While this module is usually interpreted as a Node builtin, your resolver is running inside a non-Node resolution context where such builtins are ignored. Since process isn't otherwise declared in axios's dependencies, this makes the require call ambiguous and unsound.
        Required package: process
        Required by: /Users/asdf/Documents/GitHub/yarn2-webpack5-sandbox/.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/lib/defaults/
 @ ../../.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/lib/axios.js 7:15-36
 @ ../../.yarn/cache/axios-npm-0.27.2-dbe3a48aea-38cb754046.zip/node_modules/axios/index.js 1:0-39
 @ ./src/index.js 1:0-26

webpack 5.73.0 compiled with 1 error in 635 ms

request is not managed by the pnpapi seems to tell that it’s relevant to yarn 3 environment.

If the current behavior is a bug, please provide the steps to reproduce. clone this repo and build following the guideline. Then you can see the error message above.

What is the expected behavior? The build succeeds and process get resolved correctly. If you remove the new ProviderPlugin(...) line, then the build will succeed without the wrong process resolution. If you take app package out of the workspace to make it stand alone, then the build will succeed and process will get resolved properly.

Other relevant information: webpack version: 5.73.0 Node.js version: v.16.13.2 Operating System: Mac OS Big Sur 11.6 Additional tools:

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bglgwyngcommented, Jun 9, 2022

@alexander-akait I’m sorry I’m not sure I understand your answer in the right way.

Shorty - you can’t use Node.js module in a browser

Do you mean that I shouldn’t use axios in browsers? I installed process in the package. And this solution worked well without yarn workspace. Only when I put my package inside a workspace, that error happens. I don’t know if using axios in browser is something we need to avoid, but I think that it would be better to fix the situation that some errors happen only with yarn workspace at least.

0reactions
josuevalrobcommented, Aug 19, 2022

Kind of the same issue:

[0] [0] ▲ [WARNING] [plugin @yarnpkg/esbuild-plugin-pnp] axios tried to access http. While this module is usually interpreted as a Node builtin, your resolver is running inside a non-Node resolution context where such builtins are ignored. Since http isn't otherwise declared in axios's dependencies, this makes the require call ambiguous and unsound.

Required package: http

node_modules/axios/lib/adapters/http.js:7:19:
[0] [0]       7 │ var http = require('http');
[0] [0]         ╵                    ~~~~~~

like this other 10 logs. and then it ends with:

[0] [0] Ancestor breaking the chain: axios@npm:0.27.2
[0] [0] Ancestor breaking the chain: http-proxy@npm:1.18.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error webpack dev server when using yarn workspaces
The solution is to use embedded devServer with webpack serve command, read about it here.
Read more >
webpack-dev-server | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
react-app-rewired - npm
How to rewire your create-react-app project · 1) Install react-app-rewired · 2) Create a config-overrides.js file in the root directory · 3) 'Flip' ......
Read more >
CopyWebpackPlugin | webpack
When using yarn workspaces or monorepos , relative copy paths from node_modules can be broken due to the way packages are hoisting. To...
Read more >
[Solved] Rewood 0.36.2 & webpack 5 - RedwoodJS Community
... the rw-jwt-auth-example into redwood 0.36.2 and getting a webpack 5 error I've installed the stream-browserify via: yarn workspace webbb ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found