sportsdataverse / sportsdataverse-js

Retrieves sports data from a popular sports website as well as from the NCAA website, with support for NBA, WNBA, NFL, NHL, College Football and mens and womens college basketball,
https://js.sportsdataverse.org
49 stars 12 forks source link

Error when importing #21

Closed campbelljlowman closed 7 months ago

campbelljlowman commented 11 months ago

I'm new to nodejs and I can't figure out how I'm supposed to import the package. My index.js looks like this:

const sdv = require("sportsdataverse")

But when I run it gives me this error:

/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js:4 const tabletojson = require("tabletojson").Tabletojson; ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/tabletojson/dist/lib/index.js from /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js not supported. Instead change the require of index.js in /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js to a dynamic import() which is available in all CommonJS modules. at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js:4:21) at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/app.js:6:23) at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/server.js:3:13) at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/index.js:1:13) { code: 'ERR_REQUIRE_ESM' }

Node.js v18.16.0

If I change my package type to "module", I get the same error

It doesn't seem like anyone else has had this problem, so I'm thinking it's something to do with my setup. Any help would be appreciated :)

realrufans commented 9 months ago

Hey there, I hope we are doing it the right way but I am getting same error.

image

campbelljlowman commented 9 months ago

I ended up just going into the source code and using the endpoints they use on my own API calls. That'll probably be quicker than resolving this :)