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

--all fails with ts-node (Typescript) #504

Closed
cvle opened this issue Jan 26, 2017 · 13 comments · Fixed by istanbuljs/istanbuljs.github.io#60
Closed

--all fails with ts-node (Typescript) #504

cvle opened this issue Jan 26, 2017 · 13 comments · Fixed by istanbuljs/istanbuljs.github.io#60

Comments

@cvle
Copy link

cvle commented Jan 26, 2017

First of all, great job with this project!

So I have prefect code coverage using ts-node and [email protected]. It was quiet easy to setup.

{
  "reporter": [
    "lcov",
    "text"
  ],
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx"
  ],
  "exclude": [
    "src/**/*.d.ts",
    "src/**/*.spec.ts",
    "src/**/*.spec.tsx"
  ],
  "extension": [
    ".ts",
    ".tsx"
  ],
  "require": [
    "ts-node/register"
  ]
}

But when I use { all: true } it fails like this:

/home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:321
          throw new TypeError(
                ^
TypeError: Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension and loader (attached before `ts-node`) available alongside `assemble.
d.ts`.
    at getOutput (/home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:321:17)
    at /home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:343:18
    at Object.compile (/home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:476:19)
    at Object.m._compile (/home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:406:44)
    at Module._extensions..js (module.js:550:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/vagrant/projects/typescript/reassemble/node_modules/ts-node/src/index.ts:409:12)
    at NYC._readTranspiledSource (/home/vagrant/projects/typescript/reassemble/node_modules/nyc/index.js:160:26)
    at NYC.addFile (/home/vagrant/projects/typescript/reassemble/node_modules/nyc/index.js:144:21)
    at /home/vagrant/projects/typescript/reassemble/node_modules/nyc/index.js:176:11
    at /home/vagrant/projects/typescript/reassemble/node_modules/nyc/index.js:244:5

Any idea why and how can we fix it?

@cvle
Copy link
Author

cvle commented Jan 26, 2017

The other way I tried was to do the register in mocha using --compilers tsx:ts-node/register,ts:ts-node/register. Setting { all: true } doesn't fail but it is more like a no op.

I'm coming from https://github.com/gotwarlost/istanbul and it works over there. This is the only thing keeping me from migrating all my projects from istanbul to nyc.

@cvle
Copy link
Author

cvle commented Jan 26, 2017

Sorry my bad. It works when I do the require in mocha! Time to migrate all my projects!

@cvle cvle closed this as completed Jan 26, 2017
@bcoe
Copy link
Member

bcoe commented Jan 29, 2017

@cvle nice! had a conversation with @wbyoung about this exact same issue earlier today:

#509

Where do you think we should document this caveat? would love help updating the README ... also, if you're feeling really ambitious, it would be amazing to get a TypeScript tutorial up here eventually for other folks.

@juanpicado
Copy link

@cvle what do you meant with the require thing?

@juanpicado
Copy link

Ahh, now I get it, the fix is remove the require from the nyc options body.

"require": [
   "ts-node/register"
],

and do it in this way

mocha --require ts-node/register

@JaKXz
Copy link
Member

JaKXz commented Jul 7, 2017

@juanpicado would you like to make a contribution to our docs? :)

I haven't used TypeScript in a while, so it would be nice to keep the tutorial up to date on this for the latest versions of nyc and ts-node etc from someone who has been in the trenches.

@juanpicado
Copy link

Sure ! There it goes

@felixfbecker
Copy link

felixfbecker commented Jan 25, 2018

Even with the register as part of mocha, I get the same error as with the register as part of nyc

node_modules/typescript/lib/typescript.js:89057
        ts.Debug.assert(outputText !== undefined, "Output generation failed");
                 ^
Error: Debug Failure. False expression: Output generation failed
    at Object.transpileModule (node_modules/typescript/lib/typescript.js:89057:18)
    at getOutput (node_modules/ts-node/src/index.ts:247:23)
    at Object.compile (node_modules/ts-node/src/index.ts:528:11)
    at Object.m._compile (node_modules/ts-node/src/index.ts:422:43)
    at Module._extensions..js (module.js:646:10)
    at Object.require.extensions.(anonymous function) [as .ts] (node_modules/ts-node/src/index.ts:425:12)
    at NYC._readTranspiledSource (node_modules/nyc/index.js:161:26)
    at NYC.addFile (node_modules/nyc/index.js:145:21)
    at node_modules/nyc/index.js:177:11
    at node_modules/nyc/index.js:246:5

But without --all it works fine

Yogu added a commit to AEB-labs/cruddl that referenced this issue Feb 28, 2018
This fixes "TypeError: Unable to require `.d.ts` file." from ts-node

See also istanbuljs/nyc#504
@liuxh0
Copy link

liuxh0 commented Jul 11, 2018

The solution from @juanpicado helps, but it does not solve the problem.

If I require ts-node in mocha instead of in nyc, the option all has no effect. All my ts files that is not imported by *.spec.ts will not be included. See #603

@ilyadoroshin
Copy link

ilyadoroshin commented Nov 24, 2018

"exclude": ["**/*.d.ts"] in .nycrc helped me

@grayrattus
Copy link

I had similar problem with typescript globals.d.ts
After removing
"require": [ "ts-node/register" ]
from nyc options body, everything worked. I tried many different solutions and this is the only one that worked, thanks!

@quoininc-huudatran
Copy link

"exclude": ["**/*.d.ts"] in .nycrc helped me

is failing my test coverage because i need a global.d.ts.

@diephil
Copy link

diephil commented Apr 24, 2020

"exclude": ["**/*.d.ts"] in .nycrc helped me

It did the trick for me, thanks @ilyadoroshin !

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

Successfully merging a pull request may close this issue.

10 participants