Giter VIP home page Giter VIP logo

Comments (3)

wangela avatar wangela commented on June 3, 2024

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

@ABuffSeagull 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.

from google-maps-services-js.

usefulthink avatar usefulthink commented on June 3, 2024

Hey @ABuffSeagull,

this module is very likely free of sideEffects per the webpack definition:

A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports. An example of this are polyfills, which affect the global scope and usually do not provide an export.)

However, I'd like to point out two things:

  • this package is only meant to be used in server side applications. Although it might work in certain situations, bundling it into a client-application is not officially supported or recommended. What you are seeing (importing a massive polyfill for the crypto-library) is part of the reason why.
  • from the screenshot you shared, it looks like you are using the places autocomplete service. This service (as all others) requires the serializer, which in turn needs the url-signing functions which uses crypto-functions to compute a checksum for urls in certain cases. None of that would be going away by marking the package sideEffect free.

The recommended way to use the autocomplete API in a regular client-application is either using the Maps JavaScript API or directly via fetch.

Depending on your use-case, something as simple as

async function queryAutocomplete(input) {
  const url = new URL('https://maps.googleapis.com/maps/api/place/queryautocomplete/json');
  url.searchParams.set('input', input);
  url.searchParams.set('apiKey', YOUR_API_KEY);

  const res = await fetch(url.toString());
  const data = await res.json();

  return data.predictions;
}

could already be enough.

from google-maps-services-js.

ABuffSeagull avatar ABuffSeagull commented on June 3, 2024

Hey, thanks for the response!
In my use case, I'm using Remix which colocates both server and client code in the same file, and relies on tree-shaking in order to remove the server-side code from the client-side bundle.
Without the "sideEffects": false property, the compiler does not know whether it is allowed to remove this package from the client side bundle, leading to the situation shown in the original post. You can see more info here.

from google-maps-services-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.