google-play-scraper icon indicating copy to clipboard operation
google-play-scraper copied to clipboard

TypeError: Cannot read properties of undefined (reading 'length')

Open Black995 opened this issue 2 months ago • 10 comments

I got this TypeError: Cannot read properties of undefined (reading 'length') when I called the .reviews property of the library, with the appId: "com.pregnancyrecipes". This error only happened with this app in particular, and the error displays the error in the "node_modules\google-play-scraper\lib\utils\mappingHelpers.js:73:43"

Image

Black995 avatar Oct 16 '25 17:10 Black995

+1 I'm getting the same error

Unexpected error TypeError: Cannot read properties of undefined (reading 'length')
    at Object.extractCategories (file:///Users/psoffritti/Developer/double-ape/node_modules/google-play-scraper/lib/utils/mappingHelpers.js:110:43)
    at Object.fun (file:///Users/psoffritti/Developer/double-ape/node_modules/google-play-scraper/lib/app.js:132:33)
    at file:///Users/psoffritti/Developer/double-ape/node_modules/google-play-scraper/lib/utils/scriptData.js:52:19
    at file:///Users/psoffritti/Developer/double-ape/node_modules/ramda/es/map.js:57:20
    at _arrayReduce (file:///Users/psoffritti/Developer/double-ape/node_modules/ramda/es/internal/_arrayReduce.js:6:11)
    at map (file:///Users/psoffritti/Developer/double-ape/node_modules/ramda/es/map.js:56:14)
    at file:///Users/psoffritti/Developer/double-ape/node_modules/ramda/es/internal/_dispatchable.js:44:15
    at Module.f2 (file:///Users/psoffritti/Developer/double-ape/node_modules/ramda/es/internal/_curry2.js:28:14)
    at extractFields (file:///Users/psoffritti/Developer/double-ape/node_modules/google-play-scraper/lib/utils/scriptData.js:40:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

PierfrancescoSoffritti avatar Oct 19 '25 06:10 PierfrancescoSoffritti

https://github.com/facundoolano/google-play-scraper/issues/701#issuecomment-3410466214

OR https://www.npmjs.com/package/google-play-scraper-ts

tidzh avatar Oct 19 '25 08:10 tidzh

We started having this issue and we fixed by providing the country

   const { version: android } = await gplay.app({
-    appId: app.googlePlayID
+    appId: app.googlePlayID,
+    country: app.country
   });

I also tried google-play-scraper-ts and it also needed the country, but the difference was that it didn't crash. Also the Github repository is not publicly available (see at https://www.npmjs.com/package/google-play-scraper-ts), so this is an eventually risk of security.

andrefreitas avatar Oct 20 '25 15:10 andrefreitas

Is this maybe fixed within https://github.com/facundoolano/google-play-scraper/pull/721? @facundoolano any info when you can publish this change to npm?

thanks in advance!

fgraeff avatar Oct 22 '25 11:10 fgraeff

I published, let me know if the issue is fixed so I close this.

facundoolano avatar Oct 22 '25 21:10 facundoolano

Hmm, I tried 10.1.0 and the issue was not fixed. Digging into details now.

archon810 avatar Oct 23 '25 02:10 archon810

@facundoolano Not really sure what's going on here but after updating to 10.1.0, I get this:

node:internal/modules/package_json_reader:268
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'google-play-scraper' imported from XXXXXXXXXXXX
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:854:18)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:137:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.15.1

Yet downgrading to 10.0.1 runs. Maybe something about the 10.1.0 release got forgotten or I'm missing some step?

archon810 avatar Oct 23 '25 05:10 archon810

According to Claude 4.5:

Version 10.0.1 works because: The exports field points directly to "./index.js" (which exists in the package root) When you import gplay from 'google-play-scraper', Node.js resolves it to the root index.js file No dist folder is needed Version 10.1.0 doesn't work because: The exports field points to "./dist/esm/index.js" for ESM imports This file doesn't exist because the dist folder wasn't included in the published package Node.js strictly enforces the exports field and won't fall back to other files The package was published without running the build script first This is a packaging bug in version 10.1.0 - the maintainer updated the package.json to use a built dist structure but forgot to either: Include the dist folder in the published package, or Add a prepublishOnly script to build it automatically before publishing The fix is to stay on version 10.0.1 until the maintainer publishes a corrected version (likely 10.1.1) that includes the dist folder.

Why the build doesn't run automatically The maintainer should have used one of these lifecycle hooks in their package.json: prepublishOnly - Runs before npm publish (best for this case) prepare - Runs before packing and on local install prepack - Runs before tarball is created What they have: "scripts": { "build": "./build.sh" } What they should have: "scripts": { "build": "./build.sh", "prepublishOnly": "npm run build" } This way, when the maintainer runs npm publish, it would automatically: Run prepublishOnly → which runs npm run build → which runs ./build.sh Create the dist folder Package and publish everything including the dist folder Without this lifecycle hook, the maintainer has to remember to manually run npm run build before publishing, which they clearly forgot to do for version 10.1.0. This is a common mistake when refactoring a package to use a build step - they updated the package structure but didn't add the automation to ensure the build happens before publishing.

What's the right solution here for the npm package? Does it need a fix?

I tried running npm run build but it's got some errors and it shouldn't be necessary, right?

npm run build

> [email protected] build
> ./build.sh

npm error code EUSAGE
npm error
npm error The `npm ci` command can only install with an existing package-lock.json or
npm error npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
npm error later to generate a package-lock.json file, then try again.
npm error
npm error Clean install a project
npm error
npm error Usage:
npm error npm ci
npm error
npm error Options:
npm error [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
npm error [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
npm error [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
npm error [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
npm error [--no-bin-links] [--no-fund] [--dry-run]
npm error [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm error [-ws|--workspaces] [--include-workspace-root] [--install-links]
npm error
npm error aliases: clean-install, ic, install-clean, isntall-clean
npm error
npm error Run "npm help ci" for more info
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-10-23T05_48_22_007Z-debug-0.log
./build.sh: line 14: babel: command not found
./build.sh: line 15: babel: command not found

archon810 avatar Oct 23 '25 05:10 archon810

I've been getting the same issue. Did google change their output schematics or something?

crazydaisyew avatar Oct 23 '25 12:10 crazydaisyew

@facundoolano looks like in version 10.1.0 the folder dist/esm/ is missing, which breaks the ESM import.

PierfrancescoSoffritti avatar Oct 26 '25 08:10 PierfrancescoSoffritti