Skip to content

Vue 3: ERROR: Unable to load the module "typescript". Using "ts-jest" requires this package to be installed. #285

@kleinfreund

Description

@kleinfreund

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.)

  1. Clone package.

    git clone https://github.com/kleinfreund/vue-accessible-color-picker.git
    
  2. Enter package.

    cd vue-accessible-color-picker
    
  3. Check out migrate-to-vue-version-3 branch.

    git checkout migrate-to-vue-version-3
    
  4. Install dependencies

    npm install
    
  5. Run the test for the index.js file.

    npm test -- ./src/index.test.js
    
  6. (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 replacing import Vue from 'vue' with import * as Vue from 'vue' (for some reason, Vue evaluates to undefined otherwise), the script npm test -- ./src/index.test.js passes with expected warnings.
  • After disabling the coverage settings in the jest.config.js file (i.e. removing collectCoverage and collectCoverageFrom settings), the script npm test -- ./src/index.test.js passes with expected warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdependenciesPull requests that update a dependency file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy