vuejs / vuejs/core

Importing types doesn't work in jest environment

Open
#8,301 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

has workaround
Dominant language
TypeScript
Stars
54.4k
Forks
9.2k
Avg merge
1d 5h
Merged PRs (30d)
140

Description

Vue version

3.3.2

Link to minimal reproduction

https://github.com/vojvodics/vue3.3.1-jest-reproduction-example

Steps to reproduce

Clone reproduction repository and run npm run test

What is expected?

Tests should pass

What is actually happening?

Tests are failing with the following error:

    [@vue/compiler-sfc] No fs option provided to `compileScript` in non-Node environment. File system access is required for resolving imported types.
System Info

No response

Any additional comments?

A hacky solution is provided in the repo example. It is based on these files:
https://github.com/vuejs/core/blob/v3.3.2/packages/vue/compiler-sfc/index.js
https://github.com/vuejs/core/blob/v3.3.2/packages/vue/compiler-sfc/register-ts.js

Also related:

*initially it was v3.3.1, but I updated it to v3.3.2 and it is still present

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by cloning the linked reproduction and running npm run test to reproduce the imported-types failure. Read packages/vue/compiler-sfc/index.js and packages/vue/compiler-sfc/register-ts.js, along with the linked reproduction's vue3JestHack.js, to trace the Jest environment behavior. Done means the reproduction tests pass without the hack.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.