facundoolano / google-play-scraper

Node.js scraper to get data from Google Play
MIT License
2.32k stars 629 forks source link

can't use as commonjs module with "require" #660

Closed niyogi closed 7 months ago

niyogi commented 1 year ago

Getting an error after npm installing this module and then using:

var gplay = require("google-play-scraper");

Around using import syntax. Any idea how to use this in CommonJS?

kjiang03 commented 1 year ago

do import gplay from "google-play-scraper";

morega commented 8 months ago

Getting an error after npm installing this module and then using:

var gplay = require("google-play-scraper");

Around using import syntax. Any idea how to use this in CommonJS?

Hello, the error you're encountering is because the google-play-scraper package is an ES Module, and you're trying to import it using CommonJS syntax (require). As of recent updates in Node.js, there's a distinction between CommonJS and ES Modules, and they have different import mechanisms.

To resolve this issue, you'll need to use the import statement, which is the standard syntax for ES Modules. Here's how you can modify your script:

import gplay from 'google-play-scraper';

# your code