Mapbox-gl-js: Flow reports errors about missing modules

Created on 18 Aug 2018  ยท  4Comments  ยท  Source: mapbox/mapbox-gl-js

mapbox-gl-js version: 0.48

Steps to Trigger Behavior

  1. Update mapbox-gl and Flow to latest versions
  2. Add node_modules/mapbox-gl/flow-typed to [libs] section in .flowconfig
  3. Run Flow analysis

Link to Demonstration

The problem can be seen in repo https://github.com/mikkom/onnikka by running yarn && yarn flow.

Expected Behavior

No Flow errors (at least from within mapbox-gl).

Actual Behavior

Flow reports two errors where it cannot resolve a module.

Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ node_modules/mapbox-gl/src/util/window.js:5:16

Cannot resolve module gl.

     2โ”‚
     3โ”‚ import jsdom from 'jsdom';
     4โ”‚
     5โ”‚ import gl from 'gl';
     6โ”‚ import sinon from 'sinon';
     7โ”‚ import { extend } from './util';
     8โ”‚


Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ node_modules/mapbox-gl/src/util/window.js:6:19

Cannot resolve module sinon.

     3โ”‚ import jsdom from 'jsdom';
     4โ”‚
     5โ”‚ import gl from 'gl';
     6โ”‚ import sinon from 'sinon';
     7โ”‚ import { extend } from './util';
     8โ”‚
     9โ”‚ import type {Window} from '../types/window';

Manually adding gl and sinon as dependencies in the project removes both errors but I think that should not be necessary?

workflow

Most helpful comment

[libs]
./node_modules/mapbox-gl/flow-typed
./node_modules/mapbox-gl/dist/mapbox-gl.js.flow

this fixed all of my flow issues with v50.0

All 4 comments

I encountered this same issue and worked around it by adding a "stub" declaration for the modules I wasn't already importing myself. For instance, to fix the "gl not found", I created a file flow-typed/npm/gl.js with the contents:

// @flow

declare module 'gl' {
  declare export default Function
}

Now Flow is happy and thinks the module exists.

This does seem like something the end-user shouldn't have to concern themselves with though.

I also see a reference to jsdom in src/util/window.js, which is only listed as a dev dependency in package.json.

   8 |     id: number | string | void;
   9 | 
> 10 |     _vectorTileFeature: VectorTileFeature;
     |                         ^^^^^^^^^^^^^^^^^ Cannot resolve name `VectorTileFeature`.
  11 | 
  12 |     constructor(vectorTileFeature: VectorTileFeature, z: number, x: number, y: number) {
  13 |         this.type = 'Feature';

seeing the same thing on the latest v50.0

[libs]
./node_modules/mapbox-gl/flow-typed
./node_modules/mapbox-gl/dist/mapbox-gl.js.flow

this fixed all of my flow issues with v50.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevage picture stevage  ยท  3Comments

yoursweater picture yoursweater  ยท  3Comments

stevage picture stevage  ยท  3Comments

jfirebaugh picture jfirebaugh  ยท  3Comments

PBrockmann picture PBrockmann  ยท  3Comments