Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

TypeError when creating a SourceMapGenerator from a SourceMapConsumer of an index map

Open
#345 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript
Domain
tooling

Research direction

Start with lib/source-map-generator.js around fromSourceMap and lib/util.js around relative, then reproduce the failure using the test.js example in the issue. Add a regression test for converting an index-map SourceMapConsumer, and consider the existing sourceRoot comparisons. Done means conversion no longer throws and the relevant tests pass.

Written by the indexing model from the issue text.

Description

needs-triage

When calling SourceMapGenerator.fromSourceMap with a SourceMapConsumer for an index map, the following error is thrown:

TypeError: Cannot read property 'replace' of undefined
    at Object.relative (C:\dev\scratch\source-map-test\node_modules\source-map\lib\util.js:255:17)
    at C:\dev\scratch\source-map-test\node_modules\source-map\lib\source-map-generator.js:75:31
    at Array.forEach (<anonymous>)
    at Function.fromSourceMap (C:\dev\scratch\source-map-test\node_modules\source-map\lib\source-map-generator.js:72:32)
    at test (C:\dev\scratch\source-map-test\test.js:17:52)
    at <anonymous>

test.js

const sourcemap = require("source-map");
async function test() {
    const map = { 
        file: "generated.js",
        version: 3,
        sections: [
            { offset: { column: 0, line: 0 }, map: {
                file: "part.js",
                version: 3,
                sources: ["source.js"],
                mappings: "",
                names: []
            } }
        ]
    };
    const consumer = await new sourcemap.SourceMapConsumer(map);
    const generator = sourcemap.SourceMapGenerator.fromSourceMap(consumer); // TypeError
}

The error seems to be due to a strict inequality (!==) check on sourceRoot whereas all other checks against sourceRoot use loose inequality (!=).

Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

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.

More from mozilla/source-map

All issues in mozilla/source-map

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.