i cant use hooks in react,advice? - reactjs

I'm building a react app and when i started with my first hook function I got this error
react-dom.development.js:16227
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at Object.throwInvalidHookError (react-dom.development.js:16227:1)
at useState (react.development.js:1622:1)
at MenuWrapper (menuWrapper.jsx:16:1)
at MenuList.jsx:12:1
at Array.map (<anonymous>)
at MenuList (MenuList.jsx:8:1)
at Menu.render (menu.jsx:108:1)
at finishClassComponent (react-dom.development.js:19752:1)
at updateClassComponent (react-dom.development.js:19698:1)
at beginWork (react-dom.development.js:21611:1)
react-dom.development.js:18687
The above error occurred in the <Menu> component:
at Menu (http://localhost:3000/static/js/bundle.js:385:5)
at div
at div
at App (http://localhost:3000/static/js/bundle.js:62087:78)
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.
logCapturedError # react-dom.development.js:18687
react-dom.development.js:26923
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at Object.throwInvalidHookError (react-dom.development.js:16227:1)
at useState (react.development.js:1622:1)
at MenuWrapper (menuWrapper.jsx:16:1)
at MenuList.jsx:12:1
at Array.map (<anonymous>)
at MenuList (MenuList.jsx:8:1)
at Menu.render (menu.jsx:108:1)
at finishClassComponent (react-dom.development.js:19752:1)
at updateClassComponent (react-dom.development.js:19698:1)
at beginWork (react-dom.development.js:21611:1)
this is my package.json
{
"name": "jonathan",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"#babel/runtime": "^7.5.0",
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^14.4.3",
"airbnb-prop-types": "^2.16.0",
"axios": "^1.1.3",
"bootstrap": "^5.2.2",
"create-webpack-config": "^0.2.1",
"html-webpack-plugin": "^5.5.0",
"jquery": "^3.6.1",
"mdb-react-ui-kit": "^4.2.0",
"react": "^18.2.0",
"react-bootstrap": "^2.5.0",
"react-bootstrap-accordion": "^1.0.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-onclickout": "^2.0.8",
"react-outside-click-handler": "^1.3.0",
"react-router": "^6.4.2",
"react-router-dom": "^6.4.2",
"react-script-tag": "^1.1.2",
"react-scripts": "^5.0.1",
"type-fest": "^3.1.0",
"webpack-dev-server": "^4.11.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.19.6",
"#babel/node": "^7.20.0",
"#babel/preset-env": "^7.19.4",
"#babel/preset-react": "^7.18.6",
"web-vitals": "^3.0.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}
Finally, the .jsx page that I used the usestate.
import React, { useState }from "react";
import Area from "../ReadFolder/geographicMainComponents/areaMainComponent.jsx";
import City from "../ReadFolder/geographicMainComponents/cityMainComponent.jsx";
import Country from "../ReadFolder/geographicMainComponents/countryMainComponent.jsx";
import Neighborhood from "../ReadFolder/geographicMainComponents/neighborhoodMainComponent.jsx";
import Region from "../ReadFolder/geographicMainComponents/regionMainComponent.jsx";
import { default as AreaW} from "../WriteFolder/geographicMainComponents/areaMainComponent.jsx";
import { default as CityW} from "../WriteFolder/geographicMainComponents/cityMainComponent.jsx";
import { default as CountryW} from "../WriteFolder/geographicMainComponents/countryMainComponent.jsx";
import { default as NeighborhoodW} from "../WriteFolder/geographicMainComponents/neighborhoodMainComponent.jsx";
import { default as RegionW} from "../WriteFolder/geographicMainComponents/regionMainComponent.jsx";
export function MenuWrapper(type,id,isEdit){
let [edit,setEdit] = useState(isEdit);
if(isEdit){
if(type==='country'){
return(
<div>
<div className={edit ? 'd-block' :'d-none'}><CountryW id={id}/><button onclick={() => setEdit=false}>read</button></div>
<div className={edit ? 'd-none' : 'd-block'}><Country id={id} /><button onclick={() => setEdit=true}>edit</button></div>
</div>
);
}
else{return(<div></div>)}
}
else{return(<div></div>)}
}
sorry, this is so long. please note I tried deleting the package_lock,json and node modules. then I tried npm start and even added a --force.that didn't resolve the issue.
For where I called it
import React,{Component} from "react";
import { MenuWrapper } from "./menuWrapper.jsx";
export function MenuList(Items,kind){
if(Items===null){
return(<div></div>)
}
return(
<div>
{
Items.map((item)=>{
return(
MenuWrapper(kind,item.id,false)
)
})
}
</div>
);
}

hooks can be called only within react components. MenuWrapper is not a react component (you are not invoking it as <MenuWrapper />).
You should use it as a component:
return (
<MenuWrapper kind={kind} id={item.id} ...otherProps />
);
and then:
export function MenuWrapper({ kind, id, isEdit }) {
// do stuff
}

Related

glide-data-grid / custom-cell-editing / The above error occurred in the <Editor> component / Invalid hook call

Trying to locally test Dropdown cell editing based on https://glideapps.github.io/glide-data-grid/?path=/story/extra-packages-cells--custom-cell-editing
Grid with cells rendered appropriately.
However, clicking on a cell to choose value from Dropdown, crashes and produces:
The above error occurred in the <Editor> component:
at Editor (http://localhost:3000/static/js/bundle.js:67391:12)
at div
at div
at render (http://localhost:3000/static/js/bundle.js:68194:13)
....
"above error" is
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for
one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
Code extracted and changed from https://github.com/glideapps/glide-data-grid/blob/8085cd8e0d04c865ab5963af961b734fb053ded9/packages/cells/src/cell.stories.tsx:
import * as React from 'react';
import DataEditor, {
GridCellKind,
DataEditorProps
} from "#glideapps/glide-data-grid";
import { useExtraCells, DropdownCell as DropdownRenderer, DropdownCellType } from "#glideapps/glide-data-grid-cells";
import type { DropdownCell } from "#glideapps/glide-data-grid-cells";
import "#glideapps/glide-data-grid/dist/index.css";
const defaultProps: Partial<DataEditorProps> = {
smoothScrollX: true,
smoothScrollY: true,
isDraggable: false,
rowMarkers: "none",
width: "100%",
};
export const CustomCellEditing: React.VFC = () => {
const cellProps = useExtraCells();
const data = React.useRef<string[]>([]);
return (
<DataEditor
{...defaultProps}
{...cellProps}
onPaste={true}
onCellEdited={(cell, newVal) => {
if (newVal.kind !== GridCellKind.Custom) return;
if (DropdownRenderer.isMatch(newVal)) {
data.current[cell[1]] = newVal.data.value;
}
}}
getCellsForSelection={true}
getCellContent={cell => {
const [, row] = cell;
const val = data.current[row] ?? "A";
return {
kind: GridCellKind.Custom,
allowOverlay: true,
copyData: val,
data: {
kind: "dropdown-cell",
allowedValues: ["A", "B", "C"],
value: val,
},
} as DropdownCellType;
}}
columns={[
{
title: "Dropdown",
width: 200,
},
]}
rows={5}
/>
);
};
export default CustomCellEditing;
index.html body last element:
<div id="portal" />
Config:
{
"name": "xp-ts-mui",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.10.4",
"#emotion/styled": "^11.10.4",
"#glideapps/glide-data-grid": "^5.2.1",
"#glideapps/glide-data-grid-cells": "^5.2.1",
"#mui/icons-material": "^5.10.3",
"#mui/material": "^5.10.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.5.2",
"#types/node": "^16.11.46",
"#types/react": "^18.0.15",
"#types/react-dom": "^18.0.6",
"lodash": "^4.17.21",
"marked": "^4.2.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-responsive-carousel": "^3.2.23",
"react-scripts": "5.0.1",
"styled-components": "^5.3.6",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Initial rendering success as:
Crashes when clicking Dropdown cell for selection as:
Extracted and tested another from same https://github.com/glideapps/glide-data-grid/blob/8085cd8e0d04c865ab5963af961b734fb053ded9/packages/cells/src/cell.stories.tsx example based on https://glideapps.github.io/glide-data-grid/?path=/story/extra-packages-cells--custom-cells
All other Custom Cells (e.g. Tag, DatePicker) are working fine with respective editors.
Normal behavior of Tag:
and DatePicker:
Only DropdownCell crashes when clicking for selection.
Any advice please?

renderHook causes `TooManyRerenders` error when changing state

I want to test a hook that uses states in its implementation, but each time I run my tests I get this error:
Error: Uncaught [Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.]
The hook is complex and I couldn't find which part may cause an issue (plus it works perfectly fine under real conditions, when running the application with npm start).
I tried to write a dummy test to see if I could figure out anything, and I found that updating a state (which I do in my hook) triggers the error.
Basically, this fails:
import { renderHook } from "#testing-library/react";
import React from "react";
it("foo test", () => {
const { result } = renderHook(() => {
const [foo, setFoo] = React.useState("foo");
setFoo("bar"); // This line is the culprit
return foo;
});
expect(result.current).toEqual("bar");
});
But this works:
import { renderHook } from "#testing-library/react";
import React from "react";
it("foo test", () => {
const { result } = renderHook(() => {
const [foo, setFoo] = React.useState("foo");
return foo;
});
expect(result.current).toEqual("foo");
});
What is the reason for this error and how can I fix it ?
Also, my package.json file:
{
"name": "agora-front",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.10.0",
"#emotion/styled": "^11.10.0",
"#mui/icons-material": "^5.8.4",
"#mui/material": "^5.9.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#types/react": "^18.0.15",
"#types/react-dom": "^18.0.6",
"i18next": "^21.8.16",
"i18next-browser-languagedetector": "^6.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^11.18.3",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "BROWSER=none react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --verbose",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/preset-typescript": "^7.18.6",
"#types/jest": "^28.1.6",
"jest": "^28.1.3",
"prettier": "2.7.1",
"react-test-renderer": "^18.2.0"
}
}
I got tricked by the test environment and forgot React basic good practices.
Every state update should be wrapped in a condition with useEffect, otherwise render will trigger endlessly.
I followed that practice in all my React components, thus explaining why it was working fine when building the application. But I wrote my tests a bit quickly.
For my quick example, this is the correct way to do it:
import { renderHook } from "#testing-library/react";
import React from "react";
it("foo test", () => {
const { result } = renderHook(() => {
const [foo, setFoo] = React.useState("foo");
React.useEffect(() => {
setFoo("bar"); // Now it works.
}, [])
return foo;
});
expect(result.current).toEqual("bar");
});

react-firebaseui StyledFirebaseAuth is not getting compiled

I am using react-firebaseui for authentication, according to the documentation i have written the code
import React from "react";
import StyledFirebaseAuth from "react-firebaseui/StyledFirebaseAuth";
import firebase from "firebase";
const firebaseConfig = {
...
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Configure FirebaseUI.
const uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: "popup",
// Redirect to /signedIn after sign in is successful. Alternatively you can provide a callbacks.signInSuccess function.
// signInSuccessUrl: '/signedIn',
// We will display Google and Facebook as auth providers.
signInOptions: [firebase.auth.GoogleAuthProvider.PROVIDER_ID],
};
export const SignInWith = () => (
<>
<p>Login</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} />
</>
);
but i keep getting this error
./node_modules/firebaseui/dist/esm.js
Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase').`.
I tried importing firebase using import firebase from 'firebase/app, but still the same error.
I tried commenting StyledFirebaseAuth import and tag and it is working, so I am sure the problem is with react-firebaseui.
This is my package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#reduxjs/toolkit": "^1.4.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"#types/jest": "^24.9.1",
"#types/node": "^12.19.2",
"#types/react": "^16.9.54",
"#types/react-dom": "^16.9.9",
"#types/react-redux": "^7.1.9",
"axios": "^0.21.0",
"firebase": "^8.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-firebaseui": "^4.1.0",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"typescript": "^3.8.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#types/react-router-dom": "^5.1.6",
"babel-plugin-import": "^1.13.1",
"customize-cra": "^1.0.0",
"react-app-rewired": "^2.1.6"
}
}
Thank you for any help.
Unfortunately, you've upgraded your "firebase" dependency to 8.0.0 but the "firebaseui" dependency doesn't support it yet. You will have to temporarily downgrade firebase to version 7.24.0 until firebaseui and react-firebaseui support the breaking changes in 8.0.0.
import firebase has changed with the version of 9.0.0, now there is compatibility available no need to downgrade, so you can use /compat folder in your imports,
import firebase from 'firebase/compat/app'

I can't seem to be able to use hooks in react

I'm starting a new react app. So far, nothing weird has been added. This is how my package.json looks like:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"bootstrap": "^4.4.1",
"fibers": "^5.0.0",
"jquery": "^3.5.0",
"moment": "^2.24.0",
"node-sass": "^4.14.0",
"popper": "^1.0.1",
"react": "^16.13.1",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.1",
"react-moment": "^0.9.7",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"react-thunk": "^1.0.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"sass": "^1.26.5",
"typescript": "^3.8.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Then I try the most simple of react hooks call within a component:
import React, { useState } from 'react';
const Gallery = () => {
const [test, setTest] = useState(null);
return <div>Gallery</div>;
};
export default Gallery;
But when I try to run it, I get:
Error: Invalid hook call. Hooks can only be called inside of the body
of a function component. This could happen for one of the following
reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app See https://reactjs.org/warnings/invalid-hook-call-warning.html for tips about how to debug and
fix this problem.
The package.json seems to be ok. No duplicate react versions. React is 16.8+. And the component is a functional component, not a class-based one. What could I be missing?
NOTE: When I try to run the "npm ls react" suggested in the documentation, I get no versions listed. react-dom appears correctly. Could this be the cause? And if so, any ideas of how to fix it?
Problem, can be using different version of react & react-dom dependencies
If you are using react-router-dom and have Routes like this
return (
<Router>
<Switch>
<Route path="/" component={Home} exact />
<Route path="/gallery" render={Gallery} exact />
</Switch>
</Router>
);
Here, instead of <Route path="/gallery" render={Gallery} exact /> use this <Route path="/gallery" component={Gallery} />
That, solved my problem

Gatsby - Build - WebpackError : Invariant failed

I'm having troubles building my gatsby project.
Development is working fine, but when i try to build, I get an error :
ERROR #95313
Building static HTML failed for path "/Components/Layout/Footer/"
See our docs page for more info on this error: https://gatsby.dev/debug-html
7 |
8 | if (isProduction) {
9 | throw new Error(prefix);
| ^
10 | } else {
11 | throw new Error(prefix + ": " + (message || ''));
12 | }
WebpackError: Invariant failed
- tiny-invariant.esm.js:9 invariant
[front-gatsby]/[tiny-invariant]/dist/tiny-invariant.esm.js:9:1
- react-router-dom.js:172 Object.children
[front-gatsby]/[react-router-dom]/esm/react-router-dom.js:172:132
- static-entry.js:240 Module.../../../../../front-gatsby/.cache/static-entry.js.__webpack_exports__.default
/front-gatsby/.cache/static-entry.js:240:18
- api-runner-ssr.js:19 MappingPromiseArray.PromiseArray._iterate
/front-gatsby/.cache/api-runner-ssr.js:19:1
I have no idea where to start debugging this. My website is pretty simple with some static pages and redux.
Below is my code.
I have basically a static website using redux and react router dom to navigate.
I had previously an error when building : "couldn't find the store" which is why I had to create both gatsby-browser and gatsby-ssr to enclose the Provider :
index.js:
import React, { Component } from 'react';
import './App.css';
import Navigation from './Components/Navigation'
import { library } from '#fortawesome/fontawesome-svg-core'
import { faStroopwafel, faStar, faCircle, faCheckCircle,faTimesCircle} from '#fortawesome/free-solid-svg-icons'
import 'bootstrap/dist/css/bootstrap.min.css';
class App extends Component {
render() {
library.add(faStroopwafel, faStar, faCircle, faCheckCircle, faTimesCircle)
return (
<div className="App">
<Navigation/>
</div>
);
}
}
export default App;
ReduxWrapper :
import React, { Component } from 'react';
import shop from './reducers/shop.reducer'; // importation du shop
import erreur from './reducers/erreur.reducer'; // importation du erreur
import panier from './reducers/panier.reducer'; // importation du erreur
import {Provider} from 'react-redux'; // importation du provider
import createEngine from 'redux-storage-engine-localstorage';
import {createStore, combineReducers, applyMiddleware} from 'redux'; // importation du reduceur
import * as storage from 'redux-storage'; // storage
const reducer = storage.reducer(combineReducers({shop, erreur,panier}));
const engine = createEngine('my-save-key');
const middleware = storage.createMiddleware(engine);
const createStoreWithMiddleware = applyMiddleware(middleware)(createStore);
const store = createStoreWithMiddleware(reducer);
const load = storage.createLoader(engine);
load(store);
export default ({ element }) => (
<Provider store={store}>{element}</Provider>
);
gatsby-browser & gatsby-ssr (identicals)
export { default as wrapRootElement } from './src/pages/ReduxWrapper';
My Package.json :
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing \""
},
"dependencies": {
"#feathersjs/feathers": "^4.3.0-pre.1",
"#feathersjs/rest-client": "^4.3.0-pre.1",
"#fortawesome/fontawesome-svg-core": "^1.2.18",
"#fortawesome/free-solid-svg-icons": "^5.8.2",
"#fortawesome/react-fontawesome": "^0.1.4",
"bootstrap": "^4.3.1",
"emailjs-com": "^2.4.0",
"express": "^4.17.0",
"express-favicon": "^2.0.1",
"fs": "0.0.1-security",
"gatsby": "^2.15.28",
"gatsby-plugin-mailchimp": "^5.1.2",
"gatsby-plugin-react-helmet": "^3.1.10",
"gatsby-plugin-stripe": "^1.2.3",
"react": "^16.10.1",
"react-bootstrap": "^1.0.0-beta.10",
"react-dom": "^16.10.1",
"react-helmet": "^5.2.1",
"react-redux": "^7.0.3",
"react-responsive-carousel": "^3.1.49",
"react-router-dom": "^5.0.0",
"react-router-hash-link": "^1.2.1",
"react-router-hash-link-offset": "^1.0.1",
"react-scripts": "2.1.8",
"react-scroll-to-component": "^1.0.2",
"react-stripe-checkout": "^2.6.3",
"react-stripe-elements": "^4.0.0",
"reactstrap": "^7.1.0",
"redux": "^4.0.1",
"redux-storage": "^4.1.2",
"redux-storage-engine-localstorage": "^1.1.4",
"uuid": "^3.3.3"
},
"devDependencies": {
"prettier": "^1.18.2"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
This doesn't work when running "gatsby build", it stops at the step "Building static HTML for pages" and the error above is shown
I'd bet the problem is your use of redux-storage. Gatsby can't access any browser APIs during build, so you'll need to wrap a conditional check to make sure localstorage is available (per the html debugging page that has already been suggested).
I'm not familiar with redux usage in gatsby, but I would rewrite your redux wrapper to be closer to the official example, and put the redux-storage setup in a if (typeof window !== 'undefined') block

Resources