nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

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

Closed warnellw closed 2 years ago

warnellw commented 2 years ago

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 commented 2 years ago

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.

github-actions[bot] commented 1 year ago

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.