Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gazebosx3 opened this issue May 22, 2021 · 1 comment

Comments

@gazebosx3
Copy link

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

@rmuratov
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants