Skip to content

Error in typescript but not javascript: TypeError: Cannot read property 'decode' of undefined #441

Closed

Description

@gazebosx3

I'm running into an issue where attempting to create a new SourceMapConsumer doesn't work in typescript but does in javascript. Tested with the following code:

const SourceMapConsumer = require('source-map').SourceMapConsumer

const rawSourceMap = {
    version: 3,
    file: "min.js",
    names: ["bar", "baz", "n"],
    sources: ["one.js", "two.js"],
    sourceRoot: "http://example.com/www/js/",
    mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA"
  };

async function test() {

const whatever = await new SourceMapConsumer(rawSourceMap)

console.log('whatever is: ', whatever)

}

test()

In a js file, this logs a BasicSourceMapConsumer object. In a ts file, I get the following error

property 'decode' of undefined
    at new URLStateMachine (url-state-machine.js:546)
    at Object.module.exports.basicURLParse (url-state-machine.js:1264)
    at new URLImpl (URL-impl.js:13)
    at Object.setup (URL.js:317)
    at new URL (URL.js:26)
    at util.js:179
    at Object.computeSourceURL (util.js:431)
    at source-map-consumer.js:207
    at Array.map (<anonymous>)
    at source-map-consumer.js:206

TS version is ^4.1.3

Activity

  1. rmuratov commented on Aug 24, 2023

    @rmuratov

    I have encountered the same issue. It looks like something related to whatwg-url.

    My workaround:

    1. Clone the project
    2. Update whatwg-url to the latest version (in my case, 7.0.0 -> 13.0.0)
    3. Install from own repo

    After that, it works fine. But, of course, it is super hacky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions