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 ' + ...);

  • one
    Obviously, you have problems with import: you use the 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 }); - Doigrales
  • @Doigrales figured out the synchronicity, but I can't with the library, after building everything gives an error. How can I do? - MegaRoks
  • Use require('@google/maps') , look at the result in the console, it will be clear from the result whether the ES6 import is applicable. - Doigrales
  • @Doigrales, I tried all the same error on the Error: Cannot find module '@google/maps' server. All other imports work well, except for this - MegaRoks
  • See the presence of the @google/maps folder in node_modules , if it is not there, then try npm install @google/maps again. If this does not help, try updating npm npm install -g npm and repeat the steps above. - Doigrales

0