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

bug: ESLint cannot be imported in Jest 27 #219

Closed
nickmccurdy opened this issue Sep 14, 2021 · 1 comment · Fixed by #220
Closed

bug: ESLint cannot be imported in Jest 27 #219

nickmccurdy opened this issue Sep 14, 2021 · 1 comment · Fixed by #220
Labels

Comments

@nickmccurdy
Copy link
Contributor

nickmccurdy commented Sep 14, 2021

  • kcd-scripts version: 11.2.0
  • node version: 16.9.1
  • npm (or yarn) version: 7.23.0
  • jest version: 27.2.0

Relevant code or config

import 'eslint'
// or
require('eslint')

What you did: kcd-scripts test

What happened:

[test]   ● Test suite failed to run
[test] 
[test]     TypeError: Ajv is not a constructor
[test] 
[test]       at Object.<anonymous>.module.exports (node_modules/@eslint/eslintrc/lib/shared/ajv.js:19:17)

Reproduction repository:

https://github.com/testing-library/eslint-plugin-jest-dom/tree/5cfb8c97ecc78fb4f61748fe083123bed7dc1f9e

Alternatively to reproduce without kcd-scripts, use the following Jest config:

// jest.config.js
module.exports = {
  moduleDirectories: ['node_modules', 'shared'],
}

Problem description: kcd-scripts adds 'shared' to moduleDirectories (I assume some projects might rely on this for absolute imports. Unfortunately, there is a file in ESLint in a directory called shared which has the same name as a package, and when it tries to import that package, the config causes it to import itself, and ESLint breaks with a runtime error because the script does not have the same API as the package. This blocked us from upgrading to Jest 27 in eslint-plugin-jest-dom (testing-library/eslint-plugin-jest-dom#185), which has tests relying on the ESLint rule tester.

Suggested solution: It seems like the most straightforward solution is to remove 'shared' from 'moduleDirectories'. However I'm concerned this could break back compatibility with projects that use a shared directory internally. Ideally we should figure out a way to configure Jest's module resolution so both ESLint imports and shared imports work, but I don't know how to do that myself, and reordering moduleDirectories doesn't seem to help either.

@nickmccurdy nickmccurdy changed the title Jest config breaks imports of ESLint bug: ESLint cannot be imported in Jest 27 Sep 14, 2021
@github-actions
Copy link

🎉 This issue has been resolved in version 11.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant