karma-runner / karma-runner/karma
How to disable ts-node?
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
### 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. (/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.
Contributor guide
Assessment
This issue has not been assessed yet.