bttmly / nba

Node.js client for nba.com API endpoints

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't import module (returns empty object)

danielguoo opened this issue · comments

Hi!
When I try to import this module and use it in my app, I get an empty object and all of its functions are undefined. It seems like my text editor can see these functions, but when I run it in the browser it crashes.

How are you trying to consume this package – are you using a module bundler like webpack or browserify? Or using it as a browser global? My first guess would be that you haven't configured either Babel or Webpack to understand CommonJS style modules. Since this library is primarily aimed at NodeJS usage, it uses Node's module style.

I running into the same issue. The example works fine with Node but when using webpack it returns an empty object. I can change the webpack output config to include
libraryTarget: 'commonjs2'
but then it gives an "Uncaught ReferenceError: module is not defined".
Im sure theres some configuration that needs to be set or maybe express can be used here?

I think you've helped me diagnose the problem: I'm using Create React App, which doesn't allow me to me to change my config files unless I eject, and only lets me use dependencies that have been compiled to ES5. I can find some workaround to this, but if you're willing to publish the package pre-compiled, that would be great!

Ok great, thanks for following up, I’ll look into this when I get a chance!

Awesome, thanks so much!

@danielguoo try nba@4.0.0 – should work with create-react-app and Webpack in general. let me know if any issues!

Just got it working with Webpack with no issue. Thank you so much for fixing this!

Same here- got it working with no problems. Thank you!

Thanks for the heads up folks!