Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple issues when running vite-jest: fsevents .node, jest-pnp-resolver defaultResolver, ReferenceError: __DEFINES__ #39

Open
PeterDeKok opened this issue Mar 24, 2022 · 0 comments

Comments

@PeterDeKok
Copy link

I ran into multiple issues while trying to add (vite-)jest to a vite: vanilla-ts project.

As far as I can tell, these issues are actually caused upstream and therefore not actually issues with vite or vite-jest, they seem mostly limitations of esbuild and rollup.

Also, I could not find a solution that could be implemented in vite-jest, of course I could be wrong...

However, it did stop me from using vite and vite-jest 'out-of-the-box' and therefore want to throw it out here, so other people running into the issue(s) might not have to spend a few days on finding a solution or workaround.

Reproduction:

https://github.com/PeterDeKok/reproduce_sodatea_vite-jest_dependency_errors

TLDR Below.

yarn/1.22.17 npm/8.5.0 node/v16.14.2 darwin x64

A project created with vite vanilla-ts template, with added jest and vite-jest.

Running yarn test:unit, gives the following errors:

[vite] error while updating dependencies:
Error: Build failed with 4 errors:
node_modules/fsevents/fsevents.js:13:23: ERROR: No loader is configured for ".node" files: node_modules/fsevents/fsevents.node
node_modules/jest-pnp-resolver/index.js:46:4: ERROR: Cannot assign to "defaultResolver" because it is a constant
node_modules/vite/dist/node/chunks/dep-9c153816.js:28849:7: ERROR: [plugin: vite:dep-pre-bundle] Missing "./build/defaultResolver" export in "jest-resolve" package
node_modules/vite/dist/node/chunks/dep-9c153816.js:28849:7: ERROR: [plugin: vite:dep-pre-bundle] Missing "./build/default_resolver" export in "jest-resolve" package
    at failureErrorWithLog (.../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:1599:15)
    at .../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:1245:28
    at runOnEndCallbacks (.../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:1030:63)
    at buildResponseToResult (.../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:1243:7)
    at .../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:1352:14
    at .../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:662:9
    at handleIncomingPacket (.../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:759:9)
    at Socket.readFromStdout (.../reproduce_sodatea_vite-jest_dependency_errors/node_modules/esbuild/lib/main.js:629:7)
    at Socket.emit (node:events:526:28)
    at addChunk (node:internal/streams/readable:315:12)

By excluding fsevents and jest-pnp-resolver, from dependency optimization, these errors are no longer thrown.

However, on top of 2 warnings about unsupported async import syntax, a new error pops up:

ReferenceError: __DEFINES__ is not defined

      at node_modules/vite/src/client/env.ts:17:17
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)

Possibly related issues:
evanw/esbuild#1715

TLDR;

By exluding (only) jest, from dependency optimization, all errors seem gone.

// vite.config.ts
import { defineConfig } from 'vite';

export default defineConfig({
	optimizeDeps: {
        exclude: [ 'jest' ],
    },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant