I installed the @ google / maps library.
import maps from '@google/maps'; const googleMapsClient = maps.createClient({ key: 'key', rate: { limit: 50 }, Promise: Promise }); googleMapsClient.geocode({ address: req.body.merchant_address }) .asPromise() .then((res) => { location = res.json.results[0].geometry.location; console.log('0 ' + location); }) .catch((err) => { return res.status(500).json({ err: err }); }); console.log('1 ' + location)
When building a project, the babel src --out-dir backend
in the package.json
file, when running on the server, gives the Error: Cannot find module '@google/maps'
error, why doesn’t it see '@google/maps'
?
ADDITIONAL PROBLEM: I can't make googleMapsClient
synchronous.That is, to first work the console.log('0 ' + ...);
followed by console.log('1 ' + ...);
maps
variable, but where does the confidence that the library exports it by default come from? Regarding synchronicity, you need to use a different construct, something like this:const res = await googleMapsClient.geocode({ address: req.body.merchant_address });
- Doigralesrequire('@google/maps')
, look at the result in the console, it will be clear from the result whether the ES6 import is applicable. - DoigralesError: Cannot find module '@google/maps'
server. All other imports work well, except for this - MegaRoks@google/maps
folder innode_modules
, if it is not there, then trynpm install @google/maps
again. If this does not help, try updating npmnpm install -g npm
and repeat the steps above. - Doigrales