Ts-node: v1.3.0 breaks Mocha tests

Created on 22 Aug 2016  路  6Comments  路  Source: TypeStrong/ts-node

I have been testing TypeScript source code with Mocha by passing the --compilers ts:ts-node/register option. This has worked fine up until ts-node v1.2.3. But on upgrading to v1.3.0, I get the following error:

/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/append-transform/index.js:46
            throw new Error('Can not load ' + filename + '. No require extension has been installed for ' + ext + ' files');
        ^
Error: Can not load /Users/McMath/Projects/Node/GitHub/deep-map/src/deep-map.ts. No require extension has been installed for .ts files
    at hookWasUndefined (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/append-transform/index.js:46:9)
    at require.extensions.(anonymous function) (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/ts-node/src/index.ts:302:14)
    at Object.<anonymous> (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/append-transform/index.js:67:4)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at /Users/McMath/Projects/Node/GitHub/deep-map/node_modules/mocha/lib/mocha.js:220:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/mocha/lib/mocha.js:217:14)
    at Mocha.run (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/mocha/lib/mocha.js:485:10)
    at Object.<anonymous> (/Users/McMath/Projects/Node/GitHub/deep-map/node_modules/mocha/bin/_mocha:403:18)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Function.Module.runMain (module.js:590:10)

The error can be reproduced by cloning my deep-map project. Run the following, and the tests pass:

git clone https://github.com/akim-mcmath/deep-map.git
cd deep-map
npm install && typings install && npm test

Now upgrade to v1.3.0 and the error is thrown.

npm install --save-dev [email protected]
npm test

Thank you for your attention and for your work on this project.

bug external

All 6 comments

I'm pretty sure this is not Mocha, but Istanbul. Also, I don't think the change I did was incorrect, but it looks like Istanbul might be doing something odd here.

Looks like it works if I load up ts-node _before_ instabul (ts-node node_modules/istanbul/lib/cli.js).

It looks like this was fixed in the library istanbul relies on in January. See https://github.com/istanbuljs/append-transform/issues/6.

@akim-mcmath I've opened an issue with the appropriate istanbul version. The reason this code _used_ to work with istanbul is that it would always load from the filesystem. Now, it's attempting to integrate better with the ecosystem by loading from the default loader (which is 99% from the filesystem anyway, but using the node.js file reader instead of our own in typescript). However, in this case, the old version of istanbul is falling back to throwing an error instead of following how it should work (which was been patched, just waiting on an update on istanbul's side).

Thank you for your work on this, especially given that it turned out not to be your problem. And thanks for sparing me having to file an issue with Istanbul. Your help is very much appreciated.

No worries 馃槃 Initially I was very much "WTF, how?! Oh shit" so I'm happy when it turns out to be an easy fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cevek picture cevek  路  4Comments

watzon picture watzon  路  3Comments

aj-r picture aj-r  路  3Comments

JoseLion picture JoseLion  路  3Comments

joshua-tj picture joshua-tj  路  3Comments