question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to disable ts-node?

See original GitHub issue

Expected behaviour

  • Write JavaScript code (.js files)
  • Install Karma
  • Write JavaScript test files (.js)
  • everything works great!
  • install ts-node and don’t expect anything to break.

Actual behaviour

installing ts-node causes previously-working tests to break, because Karma automatically uses ts-node, assuming that it is what I want.

Environment Details

  • Karma version (output of karma --version): 4.0.1
  • Relevant part of your karma.config.js file: N/A, there’s nothing about ts-node in there.

Steps to reproduce the behaviour

Described above.

As soon as I rm -rf node_modules/ts-node, errors go away.

Errors, for example:

19 06 2019 11:13:35.064:ERROR [config]: Invalid config file!
  TSError: ⨯ Unable to compile TypeScript:
../trusktr+builder-js-package/config/karma.config.js:3:22 - error TS7016: Could not find a declaration file for module 'globby'. '/Users/trusktr/src/trusktr+builder-js-package/node_modules/globby/index.js' implicitly has an 'any' type.
  Try `npm install @types/globby` if it exists or add a new declaration (.d.ts) file containing `declare module 'globby';`

3 const glob = require('globby')
                       ~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:6:24 - error TS7016: Could not find a declaration file for module 'mkdirp'. '/Users/trusktr/src/trusktr+builder-js-package/node_modules/mkdirp/index.js' implicitly has an 'any' type.
  Try `npm install @types/mkdirp` if it exists or add a new declaration (.d.ts) file containing `declare module 'mkdirp';`

6 const mkdirp = require('mkdirp') // mkdir -p
                         ~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:7:22 - error TS7016: Could not find a declaration file for module 'rimraf'. '/Users/trusktr/src/trusktr+builder-js-package/node_modules/rimraf/rimraf.js' implicitly has an 'any' type.
  Try `npm install @types/rimraf` if it exists or add a new declaration (.d.ts) file containing `declare module 'rimraf';`

7 const rmrf = require('rimraf') // rm -rf
                       ~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:8:19 - error TS7016: Could not find a declaration file for module 'regexr'. '/Users/trusktr/src/trusktr+builder-js-package/node_modules/regexr/index.js' implicitly has an 'any' type.
  Try `npm install @types/regexr` if it exists or add a new declaration (.d.ts) file containing `declare module 'regexr';`

8 const r = require('regexr').default
                    ~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:23:19 - error TS7006: Parameter 'file' implicitly has an 'any' type.

23 testFiles.forEach(file => {
                     ~~~~
../trusktr+builder-js-package/config/karma.config.js:45:48 - error TS7006: Parameter 'moduleName' implicitly has an 'any' type.

45                     ${nodeModulesToCompile.map(moduleName => {
                                                  ~~~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:96:27 - error TS7006: Parameter 'config' implicitly has an 'any' type.

96 module.exports = function(config) {
                             ~~~~~~
../trusktr+builder-js-package/config/karma.config.js:150:18 - error TS7006: Parameter 'fullname' implicitly has an 'any' type.

150 function dirname(fullname) {
                     ~~~~~~~~
../trusktr+builder-js-package/config/karma.config.js:157:27 - error TS7006: Parameter 'fileName' implicitly has an 'any' type.

157 function withoutExtention(fileName) {
                              ~~~~~~~~

    at createTSError (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:245:12)
    at reportTSError (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:249:19)
    at getOutput (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:362:34)
    at Object.compile (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:395:32)
    at Module.m._compile (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:473:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/trusktr/src/trusktr+infamous/node_modules/ts-node/src/index.ts:476:12)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.parseConfig (/Users/trusktr/src/trusktr+infamous/node_modules/karma/lib/config.js:351:22)
    at new Server (/Users/trusktr/src/trusktr+infamous/node_modules/karma/lib/server.js:66:24)
    at Object.exports.run (/Users/trusktr/src/trusktr+infamous/node_modules/karma/lib/cli.js:291:7)
    at Object.<anonymous> (/Users/trusktr/src/trusktr+infamous/node_modules/karma/bin/karma:3:23)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
Failed with exit code: 1

As you can see, tests break simply by installing ts-node in the project and not yet converting any tests to TypeScript.

I have a tsconfig.json file in the project, but used for other things at the moment.

It’d be nice to be able to tell Karma which tsconfig to use for test files, and to be able enable TypeScript support manually in the first place, so that there aren’t any surprises.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
trusktrcommented, Jun 19, 2019

Cool, I forked Karma, removed the register() call as in #3274, and can now get back to work!

1reaction
devoto13commented, Feb 13, 2021

Re-opening as I still want to implement a sustainable solution for this use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any way to stop ts-node-dev? - Stack Overflow
Have you tried process.exit(1)? It works in js. I think you need to install @types/node for ts? Alternatively you can use a bit...
Read more >
ts-node - npm
ts -node is a TypeScript execution engine and REPL for Node.js. It JIT transforms TypeScript into JavaScript, enabling you to directly execute ...
Read more >
Options | ts-node
Options. All command-line flags support both --camelCase and --hyphen-case . Most options can be declared in your tsconfig.json: Configuration via tsconfig.
Read more >
ts-node/README.md - UNPKG
The CDN for ts-node. ... 10, **Tip:** `ts-node` differs slightly from `tsc`. ... 133, * `--no-cache` Disable the local TypeScript Node cache ...
Read more >
Top 5 ts-node Code Examples - Snyk
onPrepare: async () => { // Transpile on the fly require('ts-node').register({ project: resolve(__dirname, './tsconfig.e2e.json') }); // Disable Angular, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found