mars / create-react-app-buildpack

⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web apps
MIT License
3.28k stars 653 forks source link

NODE_ENV being set to development in "Creating runtime environment" #115

Closed JBallin closed 6 years ago

JBallin commented 6 years ago

I've noticed other posters' build logs had their NODE_ENV being set to production (After "Creating runtime environment"). Why is mine not? I've set up an app completely from scratch following the directions on the repo.

-----> React.js (create-react-app) multi app detected
-----> Configure create-react-app build environment
       Using `NODE_ENV=development`
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=false
       NODE_VERBOSE=false
       NODE_ENV=development
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  unspecified (use default)

       Resolving node version 8.x...
       Downloading and installing node 8.11.3...
       Using default npm version: 5.6.0
       Resolving yarn version 1.x...
       Downloading and installing yarn (1.9.4)...
       Installed yarn 1.9.4
-----> Restoring cache
       Skipping cache restore (not-found)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.9.4
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info fsevents@1.2.4: The platform "linux" is incompatible with this module.
       info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
       [3/4] Linking dependencies...
       [4/4] Building fresh packages...
       Done in 25.38s.
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Pruning devDependencies
       Skipping because NODE_ENV is not 'production'
-----> Build succeeded!
=====> Downloading Buildpack: https://github.com/mars/create-react-app-inner-buildpack.git
=====> Detected Framework: React.js (create-react-app)
       Writing `static.json` to support create-react-app
       Enabling runtime environment variables
> test-build@0.1.0 build /tmp/build_9f807e7ed8235ca56a29e32dfcef543a
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
  36.94 KB  build/static/js/main.a285be49.js
  299 B     build/static/css/main.c17080f1.css
The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:
  "homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
  yarn global add serve
  serve -s build
Find out more about deployment here:
  http://bit.ly/2vY88Kr
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-static.git
=====> Detected Framework: Static HTML
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
-----> Installed directory to /app/bin
Using release configuration from last framework (Static HTML).
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 41.5M
-----> Launching...
       Released v3
       https://shielded-tor-34115.herokuapp.com/ deployed to Heroku

Also I would love a note in the README explaining why NODE_ENV is being set to development. I believe it's required for the build because our project dependencies become devDependencies for the build?

mars commented 6 years ago

create-react-app's build command, react-scripts build (called by the inner buildpack's compile script) always generates a production build, regardless of what the env variables are set too.

NODE_ENV & NPM_CONFIG_PRODUCTION are set to install the devDependencies so that the tooling is available when the production build is performed.

This buildpack only uses Node to build the javascript bundle. The runtime is an Nginx web server. NODE_ENV does absolutely nothing in the runtime.

This is explained in more detail in the architecture of this buildpack.

JBallin commented 6 years ago

@mars thanks for the response!

  1. I'm still not sure why my output looks different than other posters such as #101 and #105
  2. I read that bit but NODE_ENV isn't mentioned anywhere
mars commented 6 years ago
  1. "Runtime environment" output from the Node buildpack doesn't matter. Node is not used in the runtime.
  2. Hopefully my answers have filled in that gap.
JBallin commented 6 years ago
  1. So I'm going to assume you're saying "not sure why it's different, but it doesn't matter"
  2. I should be able to search the README for NODE_ENV and find something.
mars commented 6 years ago

NODE_ENV is now documented in README Architecture 🏙