kk55
kk55

Reputation: 51

vitest - Error: Package subpath "./utils" is not defined by "exports" in /node_modules/@vitest/runner/package.json

seeking help with this issue while trying to use react testing library with vite: Error: Package subpath "./utils" is not defined by "exports" in /node_modules/@vitest/runner/package.json

@testing-library/jest-dom: 5.17.0
@testing-library/react: 14.0.0
jsdom: 22.1.0
vite: 3.2.7
vitest: 0.34.1
react: 18.2.0

Files setup.js and relevant settings have been updated in vite.config.js

Tried to run basic test to verify that component loaded, but encountered the error above

Upvotes: 0

Views: 253

Answers (1)

oanh zg
oanh zg

Reputation: 1

The package.json in @vitest/[email protected] specifies the following:

{
   "exports": {
         // ....
         "./utils": {
             "types": "./dist/utils.d.ts",
             "import": "./dist/utils.js"
       },
   }
}

It appears that you might be using the require statement which doesn't include import condition name.

There could be some potential solutions to resolve this issue:

  • You could create a PR for @vitest/runner that include a default field under "./utils".
  • Investigate the possibility that the lack of import condition, it may be caused by transformation or others

Upvotes: 0

Related Questions