score:5
usually when you get an empty object from a require call, it's because you have circular dependencies. so you require a, which requires b, which requires c, which requires a. in that case c will get an empty object representing a, because a hasn't finished exporting its functions/objects yet and a will only be fully available to c on the next tick, when a has finished exporting.
here's an example:
// a.js
var b = require('./b');
module.exports = {
dostuff: function () {
}
}
// b.js
var c = require('./c');
// c.js
var a = require('./a');
// this will fail because a.js hasn't exported dostuff yet, since a required b, which
// required c, which required a.
a.dostuff();
the reason you get an empty object is because browserify creates an empty object representing module.exports
for that module before the module code runs. which means that another module can require it before it's finished, it's just not fully baked.
Source: stackoverflow.com
Related Query
- require (browserify) not working correctly when assigned (empty object), but works when inline
- array object working if we hardcode data but not working when we populate data from Node js to react js
- Link to not working while clicking but work when hit enter in url box
- I made a clock class in JavaScript, but it's not working properly when imported. I can only get the seconds and the interval doesn't seem to work too
- React Router work on reload, but not when clicking on a link
- evt.preventDefault is not working in IE and Edge on mouse move event, even tried evt.returnValue = false; but didn't work to stop propagation
- JSDoc does not work in local package in a Lerna monorepo project using webpack dev server but works when released to package registry
- Why does TypeScript assertion of object literal `{a}` work with interface `{a, b}` but not `{a?, b}`
- The code is working fine in codeSandbox, But showing error while doing in the IDE as "can't define property "email": Object is not extensible"
- TypeError: Object is not iterable when working with react context
- List of child components not updating correctly when deleting object from state
- Radio button not working correctly when rendered using array Data
- useState updates correctly when adding to array, but not removing
- `updater` not working correctly when using subscriptions in Relay Modern
- I get data from Api but when I try to set the value with useState it give me an empty object
- react-pdf utf8 font not working when on-fly-rendering, but works fine when render
- drag and drop not work in cypress but working by user
- React js filter not working correctly it won't return items when deleting characters
- Push object from JSON rest api into empty array not working in React
- React prevState and increment object property +1 not work correctly
- Does useState not call a rerender when working with object states?
- React test passes but component does not work properly when state updated in document.addListener handler
- Why is Array.indexOf() working correctly with one redux action but not with another? (same reducer)
- I'm working with React Route, and I have a random string, but when I do click on the link page works but when a do click again doesn't work
- JS code works when i paste it on console, but does not work inside my React App
- require is working jsx file but url() resolve is not wroking in sass file - webpack
- Ruby on Rails does not include Authorization token on header when request by axios in React, but it does work with Postman
- Trying to use react-papaparse to stream a local file row by row but it's not working - am I coding it correctly or is it just not possible?
- Database returns object but it is not displaying in JSON within my state correctly
- Json object working in return but not outside return in render
More Query from same tag
- How to use some React libraries in a class component
- Cannot pass down history prop to Component
- Loading geoJSON Markers from API - React Leaflet
- How to prevent table rows from rebuilding on update
- How to put the app in a subfolder when using create-react-app in Development mode?
- Error while running react application
- Access Webpack Dev Server on another LAN PC
- TypeError: this is undefined?
- How to add displayName to a user immediately after signing up the user in Firebase?
- import is not defined erorr using es6
- In ReactJS trying to get params but I get property 'id' does not exist on type '{}'
- To print values of an array in dropdown
- React Native, change React Navigation header styling
- React clone element to modify a child component and keep ref in a functional component
- useImperativeHandle usage for children componenent but cannot get function from parent
- Cannot read property 'destination' of undefined when react state is an array
- React, semantic-ui-react. Test suite failed to run: SyntaxError: Unexpected token import
- can't use the Refs properly in react js, Cannot read property of undefined
- how to switch language from an array with react hooks
- ReactJS - onClick doesn't work in raw javascripts
- componentDidMount, getCurrentPosition delay
- Creating a React app with 'create-react-app my-app' for the first time
- react state is not updating when it's value changes
- Requiring unknown module "498" error in ReactNative getting started example
- How to suspense the whole component before the image inside is loaded?
- Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
- How to separate searchable attributes to separate search boxes in Algolia?
- How to submit the form so that it is displayed in the table?
- How to mock 2 fetch calls with jest?
- How to dynamically render images in react?