facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.73k stars 26.86k forks source link

Unable to use 'http2' or 'dns' #4010

Closed s-maheshbabu closed 6 years ago

s-maheshbabu commented 6 years ago

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Yes.

npm --version 5.6.0

Which terms did you search for in User Guide?

create-reach-app in-built nodejs modules

Environment

  1. node -v: v9.5.0

  2. npm -v: 5.6.0

  3. yarn --version (if you use Yarn):

  4. npm ls react-scripts (if you haven’t ejected): react-scripts@1.1.1

  5. Operating system:OS X El Captain Version 10.11.6

  6. Browser and version (if relevant): Google Chrome Version 63.0.3239.132 (Official Build) (64-bit)

Steps to Reproduce

  1. create-react-app my-app
  2. vim src/index.js
  3. Add the line const http2 = require('http2');

The file should look like this -

import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import registerServiceWorker from './registerServiceWorker';

const http2 = require('http2');

ReactDOM.render(<App />, document.getElementById('root')); registerServiceWorker();

Expected Behavior

Should compile successfully because 'http2' is an in-built package as of node 9.0.0

Actual Behavior

Failed to compile.

./src/index.js Module not found: Can't resolve 'http2' in '/Users/workspace/my-app/src'

Reproducible Demo

Skipping this step since it is easy to reproduce. Just create a new app and add a line in index.js.

gaearon commented 6 years ago

Create React App gives you an HTML/JS/CSS static bundle for the browser.

There's no way built-in Node modules could work in it. They don't exist in the browser.