score:1
using global
worked for me.
const window = global.window
if (window && window.localstorage) {
const storageloglevel = window.localstorage.getitem(log_level_key)
switch (storageloglevel) {
case loglevel.debug:
loglevel = 0
break
case loglevel.info:
loglevel = 1
break
case loglevel.warning:
loglevel = 2
break
case loglevel.critical:
loglevel = 3
break
default:
loglevel = 1
}
}
score:12
it may be late to answer but it may help someone else. i also had the referenceerror: window is not defined.
issue with webpack 4, and found that adding globalobject: 'this'
line to the output
section in webpack config file fixed my problem:
output: {
globalobject: "this",
filename: "[name].js",
path: path.join(__dirname, "build/package"),
publicpath: "/resources/",
}
you can see the issue was discussed here
and the webpack documentation about the globalobject
setting here.
Source: stackoverflow.com
Related Query
- Window is not defined after a build with Webpack
- window is not defined - react-draft-wysiwyg used with next js (ssr)
- global is not defined while using socket.io-client with webpack
- window is not defined ( webpack and reactJS )
- GatsbyJS - build show error window is not defined (AOS)
- GatsbyJS Build – window is not defined / module is not defined
- ReactDom is not defined with react and webpack
- "jQuery is not defined" after require/import when use ES6 with Webpack 4
- Leaflet functions in redux-sagas with NextJS - window is not defined
- Module build failed: ReferenceError: window is not defined
- React Stripe Elements & SSR - Webpack Error: Window is Not Defined
- window is not defined in React with SSR
- Window is not defined with custom react hook
- Window is not defined with Server Side Rendering React and Express
- React build - Reference error: Window is not Defined - How to only run on client side
- Require is not defined using ReactJs with babel and webpack
- Webpack with Babel gives uncaught referenceError: require is not defined
- React not defined when installed with webpack
- Window is not defined with NextJS when using Elastic UI
- Amplify build fails with ReferenceError: license is not defined
- P5js with next.js window is not defined even in useEffect
- window.Calendly.initInlineWidget is not defined on first load but works after refresh with useEffect in React and Gatsby
- Uncaught ReferenceError: process is not defined error when converting react (TS) app to PWA with webpack and babel config
- ReferenceError: window is not defined after installing my npm package containing a D3 chart on my Next.js repo
- window is not defined webpack 3 : ReactJs
- Window is not defined in Next.js React app
- window not defined error when using extract-text-webpack-plugin React
- Webpack 5 - Uncaught ReferenceError: process is not defined
- webpack : Uncaught ReferenceError: require is not defined
- Checkbox is not `checked` after simulate `change` with enzyme
More Query from same tag
- Why input data not getting added to firebase firestore collection
- Modal windows in React
- Creating Custom UI component for android on React Native fails. App crashes
- Push dynamically added html list item into last array
- Adding a base URL to an app using Redux-Router + React-Router
- Is there a way to populate option html tag with an array in react?
- Trigger React Router state update
- react-bootstrap onSubmit doesn’t bind correctly
- Refactoring setState with callback for functional component
- How to delete multiple url params
- How to know if all the fields in a schema are filled or not?
- Best way to handle complex State in React
- How to select specific data from my mondoDB dataset
- How to render FluentUI controls in a HTML page similar to rendering React Components in a script tag inside a Div
- How to solve element type invalid error in react
- React Geosuggest doesn't update state
- setState is not updating inside componentWillReceiveProps
- how to get the specific key data from multidimensional array in react?
- Can I use hooks inside a function (not a functional component)
- Close button wont close onClick in react
- Handling 'Overlay Pages' with React Router?
- Bootstrap new row when the current is filled
- React setState doesnt update state while changing an image
- How do I center an avatar element that is within a cardHeader component?
- How should I update a component and non-component from an AJAX call?
- MultiSelect outline vairant property does not work
- Hide Html Tag When Null
- I need to add gatsby-image to my site. Need some direction
- Redux+React manage state of two (or more) same elements. How?
- How do I call a function on button click to listen for another mouse click in React Hooks?