mapbox / mapbox/mapbox-gl-js

Weird error message in misuse of addLayer()

Open
#10,007 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

api :memo:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Obviously not serious, but can be pretty confusing if you accidentally call `addLayer()` with the argument structure you expect from `addSource()`.

**mapbox-gl-js version**: 1.12.0

### Steps to Trigger Behavior

1. call `map.addLayer('mylayerid', { ... })`

### Expected Behavior

An error message like "addLayer() expects an object, not a string."

### Actual Behavior

`Uncaught TypeError: cannot use 'in' operator to search for "ref" in "mylayerid"`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the map.addLayer() entry point and reproduce the call with a string first argument to locate where the current TypeError originates. Done means the misuse produces a clear error explaining that addLayer() expects an object rather than a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.