Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No polyfills for node modules http and https with Webpack 5 (via CRA 5) #254

Closed
illume opened this issue Jan 20, 2022 · 4 comments
Closed

Comments

@illume
Copy link

illume commented Jan 20, 2022

Hello!

I upgraded to Create React App 5 recently, which newly uses Webpack 5.

Now Webpack 5 is not automagically doing polyfills for node modules anymore.

The errors are something like this (I cut out a lot of noise):

ERROR in ./node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/http.js 3:13-28
  Module not found: Error: Can't resolve 'http' in '/home/xxx/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers'
  If you want to include a polyfill, you need to:
          - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
          - install 'stream-http'

ERROR in ./node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/http.js 5:14-30
  Module not found: Error: Can't resolve 'https' in '/home/xxx/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers'
  If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
    - install 'https-browserify'

Is it possible to make @apidevtools/json-schema-ref-parser work with browsers somehow?

@jabeloep
Copy link

I am having the same issue.

@busheezy
Copy link

same issue but with vite.

@YukiGibson
Copy link

This has been quite the rabbit hole, to fix it for now I followed the error and added the fallback in the webpack.config.js:

module.exports = {
  resolve: {
    fallback: {
      https: require.resolve("https-browserify"),
      http: require.resolve("stream-http")
    },

And then installed each of those using npm install https-browserify and npm install stream-https

@jabeloep
Copy link

webpack.config.js is only available if you eject, which is something we are trying not to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants