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

An error occurred while trying to read the map file #15

Open
dan-j opened this issue Jul 19, 2017 · 6 comments
Open

An error occurred while trying to read the map file #15

dan-j opened this issue Jul 19, 2017 · 6 comments

Comments

@dan-j
Copy link

dan-j commented Jul 19, 2017

Using version 1.1.1, I get the following error and can't get round it. Downgrading to 1.1.0 fixes the issue.

It's reproducible on the most trivial example:

$ yarn add -D ts-babel-node

index.ts:

console.log('hello world');

$ ts-babel-node index.ts

/repo/node_modules/convert-source-map/index.js:40
    throw new Error('An error occurred while trying to read the map file at ' + filepath + '\n' + e);
    ^

Error: An error occurred while trying to read the map file at /repo/data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL0Rhbi9Eb2N1bWVudHMvZ2l0X3JlcG9zL3RzLXJlYWN0LWV4cHJlc3Mtc3RhcnRlci9pbmRleC50cyIsInNvdXJjZXMiOlsiL1VzZXJzL0Rhbi9Eb2N1bWVudHMvZ2l0X3JlcG9zL3RzLXJlYWN0LWV4cHJlc3Mtc3RhcnRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKCdoZWxsbyB3b3JsZCcpO1xuIl19
Error: ENOENT: no such file or directory, open '/repo/data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL0Rhbi9Eb2N1bWVudHMvZ2l0X3JlcG9zL3RzLXJlYWN0LWV4cHJlc3Mtc3RhcnRlci9pbmRleC50cyIsInNvdXJjZXMiOlsiL1VzZXJzL0Rhbi9Eb2N1bWVudHMvZ2l0X3JlcG9zL3RzLXJlYWN0LWV4cHJlc3Mtc3RhcnRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKCdoZWxsbyB3b3JsZCcpO1xuIl19'
    at readFromFileMap (/repo/node_modules/convert-source-map/index.js:40:11)
    at new Converter (/repo/node_modules/convert-source-map/index.js:47:32)
    at Object.exports.fromMapFileComment (/repo/node_modules/convert-source-map/index.js:110:10)
    at Object.exports.fromMapFileSource (/repo/node_modules/convert-source-map/index.js:122:22)
    at Module.compile (/repo/node_modules/ts-babel-node/index.js:46:36)
    at Module.<anonymous> (/repo/node_modules/ts-babel-node/index.js:89:15)
    at Module.m._compile (/repo/node_modules/ts-node/dist/index.js:219:29)
    at Module._extensions..js (module.js:580:10)
    at require.extensions.(anonymous function) (/repo/node_modules/ts-node/dist/index.js:221:16)
    at Object.hook (/repo/node_modules/ts-babel-node/index.js:42:3)
@dan-j
Copy link
Author

dan-j commented Jul 20, 2017

The first line of this function Line 56 seems to be the culprit:

function compile(base, code, filename) {
  var sourcemap = convertSourceMap.fromMapFileSource(code, '.').toObject();
  code = convertSourceMap.removeMapFileComments(code);

  var babelOutput = babel.transform(code, getBabelOpts(filename, sourcemap));

  // babelOutput has a bunch of undocumented stuff on it. Just grab what we need to save memory
  outputs[filename] = { code: babelOutput.code, map: babelOutput.map };

  return base.call(this, babelOutput.code, filename);
}

This tries to extract a file name from the source-map comment, however this module outputs source-maps as base64 encoded comments. Changing line 56 to the following fixes the issue:

<   var sourcemap = convertSourceMap.fromMapFileSource(code, '.').toObject();
---
>   var sourcemap = convertSourceMap.fromSource(code).toObject();

Happy to make a pull request, although I'd like to know how this issue doesn't already exist because it's made the module absolutely unusable for myself.

@dan-j
Copy link
Author

dan-j commented Jul 20, 2017

I've found out what's caused the issue in the first place.

I was using the most recent version of ts-node 3.2.0, ts-babel-node requires ^3.0.6. In 3.1.0 there was a change which emitted source-maps inline rather than to a separate file cache.

I've forked the repo and intend on making the fix and upgrading to ts-node 3.2.0.

@dan-j
Copy link
Author

dan-j commented Jul 20, 2017

Ok, you can't upgrade to 3.2.0 because there's a bug where it doesn't work for .tsx files.

TypeStrong/ts-node#393

Will leave this here for now, wait until ts-node have fixed their issues

@n8agrin
Copy link

n8agrin commented Jan 6, 2018

Cheers! This unblocked me after a few hours of tearing my hair out!

n8agrin added a commit to looker/ts-babel-node that referenced this issue Jan 6, 2018
@pumano
Copy link

pumano commented Mar 15, 2018

I got the same problem, any news about fix?

@dan-j
Copy link
Author

dan-j commented Mar 16, 2018

Pretty sure the creator isn't active on this anymore, I've had a Pull Request open since July which hasn't been looked at.

I'd say fork my fork https://github.com/dan-j/ts-babel-node (don't use mine, I might forget and delete it someday) it was July when I last committed to it but it fixes the issues discussed here. I'm no longer using it so won't be active on it, but I'll respond to messages if need be.

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

3 participants