npm run build error
See original GitHub issueI 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.js
last 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:
- Created 4 years ago
- Comments:13
Top GitHub Comments
I fixed it by removing
initialState
fromreducers/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 similarinitialState
and it works pretty well.Current reducer that works
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.