Vue2leaflet: build error Cannot find namespace 'L'

Created on 5 Dec 2018  Â·  17Comments  Â·  Source: vue-leaflet/Vue2Leaflet


Description


hello everyone
i use [email protected] & typescript template
but i got a build error

Steps to Reproduce

just execyarn build

Expected Results


No error is throw

Actual Results


image

Most helpful comment

Any update on this? I'm using the very same setup of @Xixi20160512. I also installed @types/leaflet, but the error persists.

UPDATE:
I solved this by adding a /types/vue2-leaflet.d.ts file to my project...

declare module 'vue2-leaflet' {
    import * as  L from 'leaflet'
    export { L }
}

All 17 comments

@HIMISOCOOL Can you help here ?

@lordfuoco Id have to install yarn and see if its reproducible that way, if @Xixi20160512 has just installed the package it should work as it is from npm cause its a dependency of this package, but it looks like you don't have @types/leaflet installed.

I just installed it via npm too and also had to manually install @types/leaflet.

@dewey thanks for letting me know, I have this in a project and haven't needed to do this so obviously I need to check it in isolation

@HIMISOCOOL hi, like @dewey I had manually install @types/leaflet too, but I got the same error.

@Xixi20160512 thanks for the heads up, I have just reproduced the issue. Its odd that my project at work doesnt encounter this issue

Any update on this? I'm using the very same setup of @Xixi20160512. I also installed @types/leaflet, but the error persists.

UPDATE:
I solved this by adding a /types/vue2-leaflet.d.ts file to my project...

declare module 'vue2-leaflet' {
    import * as  L from 'leaflet'
    export { L }
}

@JimmyBastos yep thats the quickest way to fix it. the code in master should not have the issue.

Closing this, since 2.0 does not export L at all anymore

i'm useing "vue2-leaflet": "^2.1.1", and still getting the types error (on vue-cli-service serve).

I had to install @types/leaflet and include @JimmyBastos 's declare ... file (https://github.com/KoRiGaN/Vue2Leaflet/issues/291#issuecomment-460058926) to get it running again.

Same on 2.2.1 — had to install the types and use the declare thing.

Still an issue in [email protected].
Not that experienced with types. For me adding the file didn't work, but adding the lines in types/index.d.ts solved it for me.

https://github.com/vue-leaflet/Vue2Leaflet/issues/87#issuecomment-336560312

First,
import L from 'leaflet';

then import rest modules.

I can confirm the fix: you need to manually install types: npm i -D @types/leaflet

#87 (comment)

First,
import L from 'leaflet';

then import rest modules.

When I do this I get another eslint error:
L error 'L' is defined but never used no-unused-vars.

Having this code:

import Vue from "vue";
import L from "leaflet";
import { LMap, LTileLayer, LMarker } from "vue2-leaflet";
import "leaflet/dist/leaflet.css";

export default Vue.extend({
  components: {
    "l-map": LMap,
    "l-tile-layer": LTileLayer,
    "l-marker": LMarker,
  },
});

Edit: Adding the types/vue2-leaflet.d.ts file as suggested by @JimmyBastos did the trick for me.

Hello,
FYI, today i had the same issue in my TypeScript project and most like @seisenreich, I've added shims-vue2-leaflet.d.ts with declare module 'vue2-leaflet' { import * as L from 'leaflet' export { L } } and then had to rebuild the project with npm.
Now it's working.

@Krzem0 @seisenreich should we add a FAQ section to the docs? would you be happy to add it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martinwithyou picture martinwithyou  Â·  4Comments

carlmjohnson picture carlmjohnson  Â·  4Comments

shtw picture shtw  Â·  5Comments

udos picture udos  Â·  4Comments

zaqisilverano picture zaqisilverano  Â·  4Comments