googlemaps / google-maps-services-js

Node.js client library for Google Maps API Web Services
Apache License 2.0
2.89k stars 639 forks source link

Error: Cannot find module 'core-js/modules/es.string.replace.js' #1194

Open abdirahmn1 opened 5 months ago

abdirahmn1 commented 5 months ago

Am encountering the error code MODULE_NOT_FOUND after updating the package to latest/@3.4.0, this didn't exist about 3 weeks ago. It seems to be a problem with core-js missing, temporarilly installing core-js seems to solve the problem.

Environment details

  1. Specify the API: Not API specific problem.
  2. OS type and version: Linux Mint 21.2 x86_64
  3. Library version and other environment information: lib version is @3.4.0

Steps to reproduce

  1. npm install @googlemaps/google-maps-services-js
  2. instanciate a new client
  3. simply run it

Code example

import { Client } from "@googlemaps/google-maps-services-js";
const newGmapsClient = new Client();
export default newGmapsClient;

Stack trace

node:internal/modules/cjs/loader:1077
  const err = new Error(message);
              ^

Error: Cannot find module 'core-js/modules/es.string.replace.js'
Require stack:
- /<work_dir>/node_modules/@googlemaps/url-signature/dist/index.umd.js
- /<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/serialize.js
- /<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/directions.js
- /<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/client.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at /<work_dir>/node_modules/@googlemaps/url-signature/dist/index.umd.js:1:79
    at Object.<anonymous> (/<work_dir>/node_modules/@googlemaps/url-signature/dist/index.umd.js:1:807)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/<work_dir>/node_modules/@googlemaps/url-signature/dist/index.umd.js',
    '/<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/serialize.js',
    '/<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/directions.js',
    '/<work_dir>/node_modules/@googlemaps/google-maps-services-js/dist/client.js'
  ]
}

Node.js v18.17.1

Hopefully this gets fixed soon. :+1:

wangela commented 5 months ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@abdirahmn1 Thank you for opening this issue. πŸ™ Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

justAsascha commented 5 months ago

Same error on node v20 and osx

victorighalo commented 5 months ago

Same error on node v20 and osx

Found a solution?

abdirahmn1 commented 5 months ago

Same error on node v20 and osx

Found a solution?

You can simply npm install --save core-js@3.37.0 to get rid of the problem temporarily

ArturAmpilogov commented 5 months ago

Another solution is to add the following code to the package.json:

"overrides": {
    "@googlemaps/url-signature": "1.0.32"
}
yerycs commented 5 months ago

Why don't maintainers create patch version to fix this issue? It is so discouragement to face error at the first time rather than getting response for GOOGLE MAP official sdk.

justAsascha commented 5 months ago

Why don't maintainers create patch version to fix this issue? It is so discouragement to face error at the first time rather than getting response for GOOGLE MAP official sdk.

Feel free to contribute. It's open source :)

jcardenaslie commented 5 months ago

Same error on node v20 and osx

Found a solution?

You can simply npm install --save core-js@3.37.0 to get rid of the problem temporarily

This worked for me

TimJohns commented 5 months ago

"Technically" this is a dupe of #1182, which was closed, but I'd recommend keeping this one open until the upstream releases are fixed, so that it's easier for folks to find this, and not open additional new issues.

In any case, despite the fact that google-maps-services-js is featured prominently in the call stack, 1.0.33 release requires core-js but states no dependency #528 is a little closer to the root cause, and might be a good place for additional upvotes and commentary.

In terms of @justAsascha's recommendation to make a contribution since it's Open Source, I took a full day to take a crack at it, and if I tracked it down correctly, I believe the issue is that in js-url-signature, babel is determining that core-js is required for a couple of polyfills (including es.string.replace) for older browser support. I removed core-js from the .babelrc and it all worked great FOR ME (Nodejs 20 environment), but that's pretty clearly a build config/release business decision more than a code fix. In my own personal opinion, completely removing the core-js dependency is slightly preferable, since older browsers could still use older versions explicitly, and the rest of us would have one less dependency, but that's definitely a business decision.

I conjecture someone could alternately move core-js from devDependencies to dependencies in the package.json for js-url-signature; but I didn't try that. If anyone does, tag me in the PR and I'm happy to pull it down and test here, comment, etc. Or if I run out of stuff to do and can spare another day (ha!) I'll take another crack at it.

Based on 1.0.33 release requires core-js but states no dependency #528, it sounds like folks are aware of it, but not sure who owns that decision. I recommend upvoting there.

arpithindukuri commented 5 months ago

This answer works if you don't want to install a specific version as suggested above. https://stackoverflow.com/a/72555437/14804912

After searching a lot, what works for me was what I found in this blog post:

https://blog.csdn.net/Missbelover/article/details/123221351

Basically, what you need to do is...

Remove all your node_modules dependencies. npm rm -rf node_modules

Install core-js first. npm install --save core-js

Finally install everything else. npm install yarn install

After this everything should work as expected, a least for me is working now.

Have a good day!

Thanks to Gustavo Villarroel C from Stack Overflow!

zackdotcomputer commented 3 months ago

There has been a PR to fix this issue in the underlying package here since early May. Unfortunately, there appears to be limited activity in that package compared to this one. I would encourage giving this Issue a πŸ‘ so that a review of that PR gets prioritized, as this is breaking the upgrade path for this library for some folks.

(Edit: I meant to give the πŸ‘ to the first post here - the issue itself. Google has in the past said they prioritize by those emoji on the top post.)

davidbonan commented 3 months ago

There has been a PR to fix this issue in the underlying package here since early May. Unfortunately, there appears to be limited activity in that package compared to this one. I would encourage giving this Issue a πŸ‘ so that a review of that PR gets prioritized, as this is breaking the upgrade path for this library for some folks.

πŸ‘

uriva commented 3 months ago

for deno users - npm:@googlemaps/google-maps-services-js@3.2.6 works for me

TimJohns commented 3 months ago

Looks like a new @googlemaps/url-signature (1.0.35) was released last night, but appears it did not include @zackdotcomputer's PR and still shows the issue in my environment. 1.0.33 release requires core-js but states no dependency #528:

Error: Cannot find module 'core-js/modules/es.string.replace.js'
Require stack:
- /Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/url-signature/dist/index.umd.js
- /Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/serialize.js
- /Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/directions.js
- /Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/client.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at /Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/url-signature/dist/index.umd.js:1:79
    at Object.<anonymous> (/Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/url-signature/dist/index.umd.js:1:807)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/url-signature/dist/index.umd.js',
    '/Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/serialize.js',
    '/Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/directions.js',
    '/Users/tjohns/Src/epic-roadtrip-planner/node_modules/@googlemaps/google-maps-services-js/dist/client.js'
  ]
}

Node.js v21.2.0

From package-lock.json:

    "node_modules/@googlemaps/url-signature": {
      "version": "1.0.35",
      "resolved": "https://registry.npmjs.org/@googlemaps/url-signature/-/url-signature-1.0.35.tgz",
      "integrity": "sha512-UvDUghW8bJTVSGb0G4j2eEIsUWCdVXRZlhxeCT/ZmG44lebW85v716L0ExO/m1or2DKswsZ+Bx6UUwSHDDHsIw==",
      "dependencies": {
        "crypto-js": "^4.2.0"
      }
    },
ghayward commented 3 months ago

Only way I've been able to get this to deploy is by switching to the deprecated Google Maps

npm uninstall @googlemaps/google-maps-services-js

npm install @google/maps

I'm not sure if this is advisable, but wanted to add this data point.

Very interested in better understanding what's going on here

TimJohns commented 2 months ago

FYI - I'm no longer seeing the error in my environment as of the 1.0.36 release of @googlemaps/url-signature

From my latest package-lock.json:

    "node_modules/@googlemaps/url-signature": {
      "version": "1.0.36",
      "resolved": "https://registry.npmjs.org/@googlemaps/url-signature/-/url-signature-1.0.36.tgz",
      "integrity": "sha512-BTYFuGr+DRziXiHUR0xok4t2C8apTL2plSi/ouB7yVAPxv5qiHJ05v0gO98kXfhj4r63J1ZDNku65nH/GH9T0A==",
      "dependencies": {
        "crypto-js": "^4.2.0"
      }
    },

Cross-posted from 1.0.33 release requires core-js but states no dependency #528:

I now have no overrides or core-js in my package.json. I attempted to repro in Node v21.2.0 (where I most recently confirmed I was still seeing it) and v22.4.1 (npm v10.8.1), my current environment. I'm still tying to track down the specific change that may have resolved this for me, but I'm currently lost in the details of the latest babel environment updates, and I got a little excited, so figured I'd jump over here and add a comment here real quick before digging in further.

Can anyone confirm this is resolved and/or have details of what theoretically resolved it? Fingers crossed (and thanks!)