-
-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error google compile #349
Comments
Hi @Marius-Romanus ! Could you plz run npm install and report back? Thanks! |
Hello, yes, I already did it before posting the issue, I also tried to delete all node_modules and package-lock.json in case something was wrong, and it kept giving me the error. |
Please try deleting node_modules, force checkout develop branch and run npm ci. Let me know how it goes. |
Sorry I misunderstood you, do you want my project to force in the packages to "leaflet-geosearch": "https://github.com/smeijer/leaflet-geosearch#develop". The first case I can't install develop, it gives me an error I don't know why. In the second case the error I get is this: |
I think we got lost in the translation here. 🙂 Judging from your screenshots it looks like you're going for option A which means you're trying to use it on your own project but for some reason a couple of references fail to resolve when you Could you plz share a bit more about your environment? Thanks! |
I'm sorry, i'm terrible at English and git... 🤦♂️😅 Later I will create a project from 0 to test, in case it was something uniquely mine. I'll keep you informed. If this happens to someone else and reads it, let me know if it's just me and close the issue or if it's generalized. |
Hi, I have created a new project in Angular, installed the latest version of leaflet-geosearch and simply imported { OpenStreetMapProvider } from 'leaflet-geosearch'; in app.component.ts and it gave me the same error that I mentioned at the beginning. I've created a git if you want to take a look at it: https://github.com/Marius-Romanus/bug-leaflet-geosearch |
|
Oh wait nevermind, these are compilation errors, sorry, got ahead of myself there. |
Looks like you're missing a few types. "@types/google.maps": "^3.50.2",
"@types/leaflet": "^1.8.0" Not really sure but this could be a side-effect of d58c363. I'm wondering if we can mitigate this somehow or at least document it. |
With types it works, although I don't think it's ideal if you don't need to be so restrictive and change the leaflet objects |
I know it's not. For now though it's the best I can come up with. Perhaps @smeijer could share some further insight... |
@Marius-Romanus , I agree it's not ideal, but it's how typescript works. You're importing from the root, and thereby checking types in this project. For that the google types have to be included. Instead of importing the provider from the root, it's also possible to import it via a direct import. That way, you'll only import the specific provider that you need, and will not run into the missing types error. Depending on your build stack, that might also result in a smaller bundle size. So it's worth it regardless of the error. import { Component } from '@angular/core';
import OpenStreetMapProvider from 'leaflet-geosearch/lib/providers/openStreetMapProvider';
const provider = new OpenStreetMapProvider();
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'demo-leaflet-geosearch';
} If you'll need the SearchControl as well, because you're using the leaflet search bar, you can do so like: import GeoSearchControl from 'leaflet-geosearch/lib/SearchControl';
import OpenStreetMapProvider from 'leaflet-geosearch/lib/providers/openStreetMapProvider';
const provider = new OpenStreetMapProvider();
new GeoSearchControl({
provider,
}).addTo(map); |
Hello, yes I agree, I always try to follow the types of typescript and it works for me, I only said it for other users. If you consider it you can close the issue. Thank you all very much for the project. :) |
It definitely is a side-effect of that pull request. I see three options:
The last one isn't going to work, as |
This is the typedef that we should include in declare namespace google.maps {
interface GeocoderAddressComponent {
long_name: string;
short_name: string;
types: string[];
}
interface LatLngBoundsLiteral {
east: number;
north: number;
south: number;
west: number;
}
interface LatLngLiteral {
lat: number;
lng: number;
}
interface GeocoderGeometry {
location: { toJSON(): google.maps.LatLngLiteral };
viewport: { toJSON(): google.maps.LatLngBoundsLiteral };
}
interface GeocoderResult {
address_components: google.maps.GeocoderAddressComponent[];
formatted_address: string;
geometry: google.maps.GeocoderGeometry;
partial_match?: boolean;
place_id: string;
plus_code?: unknown;//google.maps.places.PlacePlusCode;
postcode_localities?: string[];
types: string[];
}
enum GeocoderStatus {
ERROR = 'ERROR',
OK = 'OK',
ZERO_RESULTS = 'ZERO_RESULTS',
}
class Geocoder {
geocode(
request: { address?: null | string },
callback?:
((a: google.maps.GeocoderResult[]|null,
b: google.maps.GeocoderStatus) => void)|
null): Promise<{ results: google.maps.GeocoderResult[] }>;
}
} |
Is there any way we can "force" the library pull in these 2 automatically? "@types/google.maps": "^3.50.2",
"@types/leaflet": "^1.8.0" I mean if the user doesn't have to do the extra |
Hi guys, just chiming in with my 2c.. i was indeed required to include @smeijer 's suggestion of importing directly to avoid the root import did not work for me. I was also required to declare GeoSearchControl as any to get the compiler to be happy:
to avoid the error: In my package.json i have in devDependencies:
and in dependencies:
Just leaving this here for future travellers, maybe something should be added to the README because i don't think adding types to devDependencies should be seen as a 'bad' thing, as long as they don't end up in the bundle i wouldn't spend energy refactoring. Thanks for the great library :) -ivan |
Hello. I was facing the same issue, and therefore I found this thread :-) I assume the google package and it's dependencies is only for the cases, where you wanna use google instead of the OpenStreetMap. I'm really not interested in installing the google maps package, if I don't have any use of it. Is it possible to use this geosearch lib, without needing the google maps types? Kind regards |
Hello, you don't have to install the Google library, you just have to install the types in development: npm i -D @types/google.maps 🙂 |
Hi!
In the new version 3.7.0 it gives me a compilation error:
not sure if it has to do with this PR: #311
I am using node v18
Thank you very much for the great work you do!
The text was updated successfully, but these errors were encountered: