question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

import * as L from 'leaflet' gets "Can't resolve 'leaflet'" with 1.8.0-beta0

See original GitHub issue

Steps to reproduce

I have an β€˜evergreen’ Angular app (https://github.com/EOCOnline/rangertrak) It compiled fine (& runs with known issues), in VSCode, using β€œng s -o” with (with leaflet 1.7.1) Then I run npm install leaflet@1.8.0-beta.0 and now running ng s -o gets:

./src/app/entry/mini-lmap.component.ts:3:0-29 - Error: Module not found: Error: Can't resolve 'leaflet' in 'D:\Projects\RangerTrak\rangertrak\src\app\entry'

(which is yelling me about import * as L from 'leaflet')

./src/app/lmap/lmap.component.ts:2:0-31 - Error: Module not found: Error: Can't resolve 'leaflet' in 'D:\Projects\RangerTrak\rangertrak\src\app\lmap'

./node_modules/leaflet/dist/leaflet-src.js - Error: Module build failed (from ./node_modules/source-map-loader/dist/cjs.js):
Error: ENOENT: no such file or directory, open 'D:\Projects\RangerTrak\rangertrak\node_modules\leaflet\dist\leaflet-src.js'

Restarting VSCode, I get it to compile without any obvious errors, but on running I get: 3-12-2022 at 7 59 28 AM

I’m no expert on this and this could well be user error or due to other packages installed (FEEL FREE TO CLOSE THIS ISSUE if so!), but I thought you might want the feedback. I do not need any of the new features, so am happy retreating to 1.7.1 for now.

I’m super impressed at your great work, and dismayed at the war. Our hearts are with you.

Expected behavior

Current behavior

Environment

  • Leaflet version:
  • Browser (with version):
  • OS/Platform (with version):

PS:

D:\Projects\RangerTrak\rangertrak> npm list
rangertrak@0.11.38 D:\Projects\RangerTrak\rangertrak
β”œβ”€β”€ __ngcc_entry_points__.json@ extraneous
β”œβ”€β”€ @angular-devkit/build-angular@13.2.6
β”œβ”€β”€ @angular-material-components/color-picker@7.0.1
β”œβ”€β”€ @angular-material-components/datetime-picker@7.0.1
β”œβ”€β”€ @angular/animations@13.2.6
β”œβ”€β”€ @angular/cdk@13.2.6
β”œβ”€β”€ @angular/cli@13.2.6
β”œβ”€β”€ @angular/common@13.2.6
β”œβ”€β”€ @angular/compiler-cli@13.2.6
β”œβ”€β”€ @angular/compiler@13.2.6
β”œβ”€β”€ @angular/core@13.2.6
β”œβ”€β”€ @angular/fire@7.2.1
β”œβ”€β”€ @angular/flex-layout@13.0.0-beta.38
β”œβ”€β”€ @angular/forms@13.2.6
β”œβ”€β”€ @angular/google-maps@13.2.6
β”œβ”€β”€ @angular/material@13.2.6
β”œβ”€β”€ @angular/platform-browser-dynamic@13.2.6
β”œβ”€β”€ @angular/platform-browser@13.2.6
β”œβ”€β”€ @angular/router@13.2.6
β”œβ”€β”€ @angular/service-worker@13.2.6
β”œβ”€β”€ @fortawesome/fontawesome-svg-core@1.3.0
β”œβ”€β”€ @fortawesome/free-brands-svg-icons@6.0.0
β”œβ”€β”€ @fortawesome/free-regular-svg-icons@6.0.0
β”œβ”€β”€ @fortawesome/free-solid-svg-icons@6.0.0
β”œβ”€β”€ @googlemaps/markerclusterer@1.0.26
β”œβ”€β”€ @material/banner@13.0.0
β”œβ”€β”€ @material/slider@13.0.0
β”œβ”€β”€ @material/switch@13.0.0
β”œβ”€β”€ @mdi/js@6.5.95
β”œβ”€β”€ @ngx-pwa/local-storage@13.0.2
β”œβ”€β”€ @popperjs/core@2.11.2
β”œβ”€β”€ @types/google-maps@3.2.3
β”œβ”€β”€ @types/google.maps@3.48.2
β”œβ”€β”€ @types/jasmine@3.10.3
β”œβ”€β”€ @types/leaflet.markercluster@1.4.6
β”œβ”€β”€ @types/leaflet@1.7.9
β”œβ”€β”€ @types/node@17.0.21
β”œβ”€β”€ @types/supercluster@7.1.0
β”œβ”€β”€ @what3words/api@4.0.5
β”œβ”€β”€ ag-grid-angular@27.0.0
β”œβ”€β”€ ag-grid-community@27.0.1
β”œβ”€β”€ chalk@4.1.2
β”œβ”€β”€ cross-conf-env@1.2.1
β”œβ”€β”€ dayjs@1.10.8
β”œβ”€β”€ dev-norms@1.7.1
β”œβ”€β”€ firebase@9.6.8
β”œβ”€β”€ http-server@14.1.0
β”œβ”€β”€ idb@7.0.0
β”œβ”€β”€ import-sort-cli@6.0.0
β”œβ”€β”€ import-sort-parser-typescript@6.0.0
β”œβ”€β”€ import-sort-style-module@6.0.0
β”œβ”€β”€ import-sort@6.0.0
β”œβ”€β”€ init-dev-env@1.0.0
β”œβ”€β”€ jasmine-core@4.0.1
β”œβ”€β”€ js-beautify@1.14.0
β”œβ”€β”€ jshint@2.13.4
β”œβ”€β”€ karma-chrome-launcher@3.1.1
β”œβ”€β”€ karma-coverage@2.2.0
β”œβ”€β”€ karma-jasmine-html-reporter@1.7.0
β”œβ”€β”€ karma-jasmine@4.0.1
β”œβ”€β”€ karma@6.3.17
β”œβ”€β”€ leaflet.markercluster@1.5.3
β”œβ”€β”€ leaflet.offline@2.1.0
β”œβ”€β”€ leaflet@1.8.0-beta.0
β”œβ”€β”€ npm-run-all@4.1.5
β”œβ”€β”€ prettier@2.5.1
β”œβ”€β”€ rimraf@3.0.2
β”œβ”€β”€ rxfire@6.0.3
β”œβ”€β”€ rxjs@7.5.5
β”œβ”€β”€ tslib@2.3.1
β”œβ”€β”€ tslint-config-prettier@1.18.0
β”œβ”€β”€ tslint-etc@1.13.10
β”œβ”€β”€ tslint-plugin-prettier@2.3.0
β”œβ”€β”€ tslint@6.1.3
β”œβ”€β”€ tsviz-cli@2.0.3
β”œβ”€β”€ typescript@4.5.5
β”œβ”€β”€ xlsx-style@0.8.13
β”œβ”€β”€ xlsx@0.18.3
└── zone.js@0.11.5

on a desktop with Windows 10 & latest Chrome browser

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
BButnercommented, Mar 22, 2022

I’m doing Angular & Typescript, & have incorporated leaflet.MarkerCluster & leaflet.offline.

I think I’ve uninstalled & removed them from package.json, angular.json, uninstalled the @type files, then added the ref to the main script from the Amazon CDN, and still get "Cannot find module 'leaflet' or its corresponding type declarations.ts(2307)" when I try to do either: import * as L from 'leaflet' or import { tileLayer, latLng, control, marker, icon, divIcon, LatLngBounds, Map, MapOptions } from 'leaflet'

I easily could have missed something as there are a bunch of potential pitfalls, so will await the next beta & re-verify this still exists then. (As I noted I’m not reliant on any new functionality, just trying to help test - so certainly don’t want to waste your time either!)

Its much easier to just clone the project, run npm install, then do npm run build, then run npm link from the root of the project directory, then go into your project and to npm link leaflet.

I did this, and was able to resolve the issue originally in this issue, and resolve the issue I was originally experiencing that was making me want to update.

So to confirm with @Falke-Design and @jonkoops, this did indeed resolve the issue with β€œCan’t resolve β€˜leaflet’” for me.

2reactions
Falke-Designcommented, Mar 21, 2022

@BButner @VashJuan You can access the main build over https://leafletjs-cdn.s3.amazonaws.com/content/leaflet/main/leaflet-src.js You can download it and use it directly instead of useing the the npm package

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing leaflet into module from cdn with typescript support
Anyone know how to fix this? I don't want to use a bundler. Edit As jsejcksn suggested in the comments, importing a ES...
Read more >
@types/leaflet - npm
Summary. This package contains type definitions for Leaflet.js (https://github.com/Leaflet/Leaflet). Details.
Read more >
Couldn't draw polygons/polylines using Leaflet in React
I could easily draw rectangle, circle and markers as well, but I am not able to draw polygon or polyline. Here is my...
Read more >
@react-leaflet/core | Yarn - Package Manager
Updated Leaflet dependency to v1.9. Fixed eventHandlers object being injected in WMS request URL. Added support for dynamic bounds props on ImageOverlay ....
Read more >
Installation - React Leaflet
This documentation assumes you are already familiar with React and have a project setup. If it is not the case, you should read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found