Description
Issue
I’m playing around with migrating a package to Vue 3 and upgraded a couple of its dependencies including vue-jest to v5.0.0-alpha.5. When running a small test for a JavaScript file which is importing a Vue single file component, I receive the following error from vue-jest:
ERROR: Unable to load the module "typescript". Using "ts-jest" requires this package to be installed.
Full error
Running coverage on untested files...Failed to collect coverage from /home/phil/dev/packages/vue-accessible-color-picker/src/ColorPicker.vue
ERROR: Unable to load the module "typescript". Using "ts-jest" requires this package to be installed. To fix it:
↳ install "typescript": `npm i -D typescript` (or `yarn add --dev typescript`)
STACK: Error: Unable to load the module "typescript". Using "ts-jest" requires this package to be installed. To fix it:
↳ install "typescript": `npm i -D typescript` (or `yarn add --dev typescript`)
at Importer._import (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/util/importer.js:143:15)
at Importer.typescript (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/util/importer.js:74:21)
at ConfigSet.get (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/config/config-set.js:384:40)
at ConfigSet.compilerModule (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/util/memoize.js:43:24)
at ConfigSet.readTsConfig (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/config/config-set.js:625:23)
at ConfigSet.get (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/config/config-set.js:313:31)
at ConfigSet._typescript (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/util/memoize.js:43:24)
at ConfigSet.get [as typescript] (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/ts-jest/dist/config/config-set.js:283:25)
at getTsJestConfig (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/vue-jest/lib/utils.js:71:30)
at processTemplate (/home/phil/dev/packages/vue-accessible-color-picker/node_modules/vue-jest/lib/process.js:72:20)
It seems that some part of the code is requiring the ts-jest package which I don’t have installed because my package is not using TypeScript. It seems that some part of the code is requiring the typescript via the ts-jest package which is installed as part of the vue-jest package. However, my project doesn’t use TypeScript at all. I suspect the issue starts happening in https://github.com/vuejs/vue-jest/blob/next/lib/process.js (in particular around https://github.com/vuejs/vue-jest/blob/next/lib/process.js#L63-L72). Logging { tsconfig }
after the line containing const tsconfig = getTsJestConfig(config)
does not log anything. The utils function for retrieving the jest configuration for TypeScript in https://github.com/vuejs/vue-jest/blob/next/lib/utils.js#L69 seems to be returning a configSet
variable missing the properties that being used on the next line.
Reproduction
(This isn’t exactly a minimal reproduction case, but I believe the issue is largely independent from how my package is structured or written.)
-
Clone package.
git clone https://github.com/kleinfreund/vue-accessible-color-picker.git
-
Enter package.
cd vue-accessible-color-picker
-
Check out
migrate-to-vue-version-3
branch.git checkout migrate-to-vue-version-3
-
Install dependencies
npm install
-
Run the test for the index.js file.
npm test -- ./src/index.test.js
-
(Optional) Install typescript and re-run the test in step 5 to see the issue fixed.
npm install --save-dev typescript
Notes
- Related pull request removing a depenency on the typescript package: Gate typescript behind tsconfig check and added e2e test for project that doesn't use Typescript (Fix #282) #283
- After installing TypeScript (using
npm install --save-dev typescript
) and replacingimport Vue from 'vue'
withimport * as Vue from 'vue'
(for some reason,Vue
evaluates toundefined
otherwise), the scriptnpm test -- ./src/index.test.js
passes with expected warnings. - After disabling the coverage settings in the jest.config.js file (i.e. removing
collectCoverage
andcollectCoverageFrom
settings), the scriptnpm test -- ./src/index.test.js
passes with expected warnings.