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

Next.js apps fail to lint with jest.config.ts #9982

Closed
warnellw opened this issue Apr 24, 2022 · 2 comments · Fixed by #10035
Closed

Next.js apps fail to lint with jest.config.ts #9982

warnellw opened this issue Apr 24, 2022 · 2 comments · Fixed by #10035
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@warnellw
Copy link

warnellw commented Apr 24, 2022

Current Behavior

Newer Nx projects that have run the jest.config.js -> jest.config.ts migration (or brand new workspaces) fail to lint Next.js applications due to a bug with how the jest.config.ts is included/excluded in the tsconfig.*.json files.

Expected Behavior

A Next.js app should lint successfully just as it did prior to the conversion from jest.config.js -> jest.config.ts.

Steps to Reproduce

  1. Create an empty Nx workspace@latest
  2. Generate a Next.js app with the setParserOptionsProject flag
  3. Attempt to lint the Next.js app via npx nx lint your-next-app

It appears the jest.config.ts is excluded in tsconfig.json, and included in the tsconfig.spec.json. However, the inclusion does not appear to be working properly (see error below).

Failure Logs

  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: apps/next/jest.config.ts.
The file must be included in at least one of the projects provided

Environment

Node : 14.17.6
OS : darwin x64
npm : 6.14.15

nx : 14.0.2
@nrwl/angular : Not Found
@nrwl/cypress : 14.0.2
@nrwl/detox : Not Found
@nrwl/devkit : 13.10.2
@nrwl/eslint-plugin-nx : 14.0.2
@nrwl/express : Not Found
@nrwl/jest : 14.0.2
@nrwl/js : 14.0.2
@nrwl/linter : 14.0.2
@nrwl/nest : Not Found
@nrwl/next : 14.0.2
@nrwl/node : Not Found
@nrwl/nx-cloud : 13.3.1
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.0.2
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.0.2
@nrwl/web : 14.0.2
@nrwl/workspace : 14.0.2
typescript : 4.6.3
rxjs : 6.6.7

@warnellw
Copy link
Author

I have found a temporary solution: adding an explicit excludes: ["node_modules"] (omitting the jest.config.ts) to the tsconfig.spec.json effectively overrides the excludes inherited from the tsconfig.json, allowing the jest.config.ts to properly be included and the linting to pass. I am not an expert in Typescript configuration, but it does not appear that includes takes precedence over excludes (in fact, the opposite appears to be the case). It may be wise to migrate the Next.js Typescript configuration to a 3-file config pattern similar to Node apps in order to avoid the inheritance issue.

@barbados-clemens barbados-clemens self-assigned this Apr 25, 2022
@barbados-clemens barbados-clemens added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Apr 25, 2022
barbados-clemens added a commit that referenced this issue May 11, 2022
…e `export default` (#10035)

* fix(testing): jest.preset.ts => jest.preset.js

* fix(testing): update to export default

* fix(testing): migration for moving to export default

* fix(testing): add eslint ignore comments for jest config properties

fixes: #10021

* fix(testing): update tsconfig.spec.json for next apps with project parserOptions

fixes: #9982

* fix(testing): prevent renaming root jest preset

fixes: #9973

* fix(testing): update snapshots for export default

* fix(testing): bump migration version to run

* fix(testing): make sure default jest tests pass for various projects

* fix(js): generate correct jest config for --compiler=swc --js
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants