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.

npm run build error

See original GitHub issue

I can’t run npm run build last two weeks. It worked good until September. But now I have the error when trying to run npm run build.

I’ve decided to check all commits to figure out when npm run build had worked… And now I can’t build the project even with commit from 4th July when I first time had implemented React. There is always this error. But it worked in August. My last successful deploy was on 1st September! Everything worked.

Here is the error:

> client@0.1.0 build /Users/Anton/projects/focus/client
> react-scripts build

Creating an optimized production build...
Failed to compile.

./src/reducers/alert.js
TypeError: Cannot read property 'name' of null
    at Array.filter (<anonymous>)


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Anton/.npm/_logs/2019-09-21T12_59_33_899Z-debug.log

I updated reducers/alert.jslast time 3 months ago.

Here is reducers/alert.js:

import { SET_ALERT, REMOVE_ALERT } from '../actions/types';

const initialState = [];

export default function(state = initialState, action) {
  const { type, payload } = action;

  switch (type) {
    case SET_ALERT:
      return [...state, payload];
    case REMOVE_ALERT:
      return state.filter(alert => alert.id !== payload);
    default:
      return state;
  }
}

The problem is here return [...state, payload] in reducers/alert.js. When I comment this line of code, it works. When I change on return [...initialState, payload] or return [...something, payload] - it works. In these cases, I can run npm run build and everything is fine. But when I use return [...state, payload] that had worked in July and August, I have gotten the error now.

Here is actions/alert.js that dispatch with payload to reducers/alert.js:

export const setAlert = (msg, alertType, timeout = 5000) => dispatch => {
  const id = uuid.v4();

  dispatch({
    type: SET_ALERT,
    payload: { msg, alertType, id }
  });

  setTimeout(() => dispatch({ type: REMOVE_ALERT, payload: id }), timeout);
};

How to fix it? Why npm run build doesn’t work with return [...state, payload] now?

My Environment:

“react-scripts”: “3.1.1” or “3.1.2” (I’ve tried to build with two versions) create-react-app --version: 2.1.5 npm --version: 6.11.3 npx create-react-app --info:

Environment Info:

  System:
    OS: OS X El Capitan 10.11.6
    CPU: x64 Intel(R) Core(TM)2 Duo CPU     L9400  @ 1.86GHz
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    npm: 6.11.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 77.0.3865.90
    Firefox: 65.0.1
    Safari: 11.1.2
  npmPackages:
    react: ^16.9.0 => 16.9.0 
    react-dom: ^16.9.0 => 16.9.0 
    react-scripts: ^3.1.2 => 3.1.2 
  npmGlobalPackages:
    create-react-app: 2.1.5

Here is a complete log of this run:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.11.3
3 info using node@v10.15.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle client@0.1.0~prebuild: client@0.1.0
6 info lifecycle client@0.1.0~build: client@0.1.0
7 verbose lifecycle client@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle client@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/Anton/projects/focus/client/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/mongodb/bin:/usr/local/mongodb/bin
9 verbose lifecycle client@0.1.0~build: CWD: /Users/Anton/projects/focus/client
10 silly lifecycle client@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle client@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle client@0.1.0~build: Failed to exec build script
13 verbose stack Error: client@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid client@0.1.0
15 verbose cwd /Users/Anton/projects/focus/client
16 verbose Darwin 15.6.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.15.0
19 verbose npm  v6.11.3
20 error code ELIFECYCLE
21 error errno 1
22 error client@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the client@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
a007mrcommented, Sep 26, 2019

I fixed it by removing initialState from reducers/alerts.js. It helps to build and deploy the app. But I’m still looking for the solid solution of the core problem because I have other reducers with similar initialState and it works pretty well.

Current reducer that works

// const initialState = [];

export default function(state = [], action) {...})
0reactions
stale[bot]commented, Jan 6, 2020

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors when running npm run build - node.js - Stack Overflow
Im trying to create my built folder for a react project, but I get this error when I run the command 'npm run...
Read more >
Execution of "npm run build" causes an error and can not be ...
I purchased Material Dashboard Pro React.(material-dashboard-pro-react@1.2.0) Execution of "npm run build" causes an error and can not be ...
Read more >
A new Error: Command "npm run build" exited with 1 - Get Help
Hi every one ! I try to deploy my project on vercel but It doesn't work. I tried to : change my package.json...
Read more >
"npm build / npm run build" shows error : r/reactjs - Reddit
"npm build / npm run build" shows error · Tried running `npm run-script build` · Tried doing `npm cache clean --force` · Tried...
Read more >
Common errors | npm Docs
Random errors · Some strange issues can be resolved by simply running npm cache clean and trying again. · If you are having...
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