20403 (1) [Avatar] Offline
#1
I was seeing this error when running
npm run dev


ERROR in ./src/index.js
Module build failed: Error: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: undefined. (While processing preset: "/Users/kevin/Documents/letters-social/node_modules/babel-preset-react-app/index.js")
    at Object.<anonymous> (/Users/kevin/Documents/letters-social/node_modules/babel-preset-react-app/index.js:47:9)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at /Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:296:17
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/index.js:135:24)
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./src/index


To fix I needed to change this line in /package.json from:
"dev": "npm-run-all -p api client:dev server:dev styles:w",

to:
"dev": "NODE_ENV=development npm-run-all -p api client:dev server:dev styles:w",


In case anyone else runs into it!
tempusfugit (144) [Avatar] Offline
#2
Once you get past that hurdle, running
npm run dev

you may also note this error
SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (/letters-social/server/server.js:18:47)
    at Module._compile (module.js:641:30)
    at loader (/letters-social/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/letters-social/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)

coming up.

It's generated by server/server.js - in particular:
firebase.initializeApp({
    credential: firebase.credential.cert(JSON.parse(process.env.LETTERS_FIREBASE_ADMIN_KEY)),
    databaseURL: 'https://letters-social.firebaseio.com'
});

The error can be silenced with
const firebase_admin_key = process.env.LETTERS_FIREBASE_ADMIN_KEY;
const credential = firebase_admin_key ?
      firebase.credential.cert(JSON.parse(firebase_admin_key)) :
      firebase.credential.applicationDefault();
firebase.initializeApp({
  credential,
  databaseURL: 'https://letters-social.firebaseio.com'
});
ptmy (22) [Avatar] Offline
#3
Got the exact same error as mentioned by the original poster of this thread when I was trying to run the example from chapter 4; fixed it using his suggestions. Now I run into this:

pm@T5600U:~/Books/ReactInAction/letters-social$ npm run dev

> letters-social@1.0.0 dev /home/pm/Books/ReactInAction/letters-social
> NODE_ENV=development npm-run-all -p api client:dev server:dev styles:w


> letters-social@1.0.0 api /home/pm/Books/ReactInAction/letters-social
> nodemon -x 'node -r @std/esm ./db/run.js --inspect'


> letters-social@1.0.0 styles:w /home/pm/Books/ReactInAction/letters-social
> npm run styles && node-sass src/styles/styles.scss -o static/ -w src/styles --watch --recursive


> letters-social@1.0.0 server:dev /home/pm/Books/ReactInAction/letters-social
> nodemon --config nodemon.json index.js


> letters-social@1.0.0 client:dev /home/pm/Books/ReactInAction/letters-social
> webpack-dev-server --config ./build/webpack.config.js

[nodemon] 1.12.1
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node -r @std/esm ./db/run.js --inspect`

> letters-social@1.0.0 styles /home/pm/Books/ReactInAction/letters-social
> node-sass -q src/styles/styles.scss -o static/

JSON Server is running
==> ??  Newsfeed is running on port 3100 ?
Project is running at http://localhost:3000/
webpack output is served from http://localhost:3000/
404s will fallback to /index.html
Hash: b568558ae70098ef89ee
Version: webpack 3.6.0
Time: 5439ms
 7 assets
[./node_modules/url/url.js] ./node_modules/url/url.js 23.3 kB {0} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:3000] (webpack)-dev-server/client?http://localhost:3000 7.23 kB {0} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.73 kB {0} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.04 kB {0} [built]
[./node_modules/webpack/hot ^\.\/log$] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
[./node_modules/webpack/hot/dev-server.js] (webpack)/hot/dev-server.js 1.61 kB {0} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {0} [built]
[./node_modules/webpack/hot/log-apply-result.js] (webpack)/hot/log-apply-result.js 1.31 kB {0} [built]
[./node_modules/webpack/hot/log.js] (webpack)/hot/log.js 1.04 kB {0} [built]
   [0] multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./src/index 52 bytes {0} [built]
[./src/app.js] ./src/app.js 10.8 kB {0} [built]
[./src/index.js] ./src/index.js 795 bytes {0} [built]
[./src/shared/crash.js] ./src/shared/crash.js 157 bytes {0} [built]
[./src/shared/vendor.js] ./src/shared/vendor.js 121 bytes {0} [built]
[./src/styles/styles.scss] ./src/styles/styles.scss 1.21 kB {0} [built]
    + 263 hidden modules

ERROR in ./src/components/post/Post.js
Module not found: Error: Can't resolve '../map/DisplayMap' in '/home/pm/Books/ReactInAction/letters-social/src/components/post'
 @ ./src/components/post/Post.js 43:18-46
 @ ./src/app.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./src/index
Child html-webpack-plugin for "index.html":
     1 asset
    [./node_modules/html-webpack-plugin/lib/loader.js!./src/index.ejs] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.ejs 5.03 kB {0} [built]
    [./node_modules/lodash/lodash.js] ./node_modules/lodash/lodash.js 540 kB {0} [built]
    [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {0} [built]
    [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 517 bytes {0} [built]
webpack: Failed to compile.



It's really a big turn-off to run into problems like these when trying examples from a supposedly intro tech book on a topic. The original post of this thread is dated Jan 2018. It's now Jun 2018, and there's no reply from the author. Is he still around?

I wish the author would fix problems such as these, so readers can actually follow what he's trying to say in the book.
mark (56) [Avatar] Offline
#4
Hey there!
I'll take some time to address this this weekend. Sorry for the trouble!
mark (56) [Avatar] Offline
#5
126331 (1) [Avatar] Offline
#6
20403 wrote:I was seeing this error when running
npm run dev


ERROR in ./src/index.js
Module build failed: Error: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: undefined. (While processing preset: "/Users/kevin/Documents/letters-social/node_modules/babel-preset-react-app/index.js")
    at Object.<anonymous> (/Users/kevin/Documents/letters-social/node_modules/babel-preset-react-app/index.js:47:9)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at /Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:296:17
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/kevin/Documents/letters-social/node_modules/babel-core/lib/transformation/file/index.js:135:24)
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./src/index


To fix I needed to change this line in /package.json from:
"dev": "npm-run-all -p api client:dev server:dev styles:w",

to:
"dev": "NODE_ENV=development npm-run-all -p api client:dev server:dev styles:w",


In case anyone else runs into it!


This helped me. Thanks!