nx: Lint affected doesn't work after 14.2.4 => 14.3.* migration

Current Behavior

nx affected:lint --base=main fails with '_' is not found in schema error after 14.2.4 => 14.3.* migration. Linting of individual libs working fine. With 14.2.4 version affected linting working fine too.

Expected Behavior

Lint works

Failure Logs

'_' is not found in schema
 >  NX   Running target "lint" failed

Environment

Node : 16.14.2
OS   : win32 x64
npm  : 8.5.0

nx : 14.3.5
@nrwl/angular : 14.3.5
typescript : 4.7.3
---------------------------------------
Community plugins:
    @storybook/angular: 6.5.9

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Hi @gxxcastillo, the error I believe originates from @Phillip9587’s nx-stylelint (if that is what your stylelint target uses as an executor). I have created a PR that should fix this: https://github.com/Phillip9587/nx-stylelint/pull/336 but you will have to wait until Philip checks it, approves it, and releases a new version.

Hi @meeroslav, thanks for your work on this issue. I see issues https://github.com/nrwl/nx/pull/10847, https://github.com/nrwl/nx/pull/10848, https://github.com/nrwl/nx/commit/6a65101ec239f1b3eae28734e4109b56a3700599, and https://github.com/nrwl/nx/issues/10806. I’ve updated to NX 14.4.0, and while I’m no longer getting '_' is not found in schema, I am now getting NX Schema does not support positional arguments. Argument <...list of files from my commit...>. Is this related to the same problem? Anything I need to do?

I’m using lintstaged with eslint, stylelint, and prettier - in that order. Eslint is passing (it wasn’t before upgrading to 14.4.0) but things now break with stylelint.

This is what my linstagedrc looks like (this has been working for the last 6months):

{
  "*": [
    "nx affected:lint --fix --base=main --head=HEAD",
    "nx affected --target=stylelint --fix --base=main --head=HEAD",
    "nx format:write"
  ]
}

This fix will be contained in the next version - either 14.4.0 or 14.3.7, whichever comes next.

Check this commit - https://github.com/nrwl/nx/commit/6a65101ec239f1b3eae28734e4109b56a3700599.

In the next version, you will be able to define fileset pattern/glob per target to ensure target is affected only by a subset of files - e.g. build should not care about spec files, while test cares about both.

Otherwise, you can always use params that underlying libraries (jest, estlint, etc.) define - linting just a single file or running tests that match a certain pattern.

Thanks, @sluger,

That helped me find the issue. The difference between running those two scripts is that lint-staged appends the path to the file, and the linter does not expect any positional parameters leading to an unfortunate error with a cryptic message.

The same can be reproduced with:

npx nx lint my-project sometext

I’ll look into a fix now.

Hi @meeroslav!

I have set up a minimal NX repo with Typescript React here: https://github.com/sluger/nx-issue-lint-affected

With versions and commands on MacOs 12.3.1 with nx version 14.3.6:

$ node --version
v16.15.0


$ npm --version
8.5.5


$ npx create-nx-workspace@latest
✔ Workspace name (e.g., org name)     · nx-issue-lint-affected
✔ What to create in the new workspace · react
✔ Application name                    · react-web-app
✔ Default stylesheet format           · @emotion/styled
✔ Use Nx Cloud? (It's free and doesn't require registration.) · No
>  NX   Nx is creating your v14.3.6 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✔ Nx has successfully created the workspace.

$ npx mrm@2 lint-staged

Steps to Reproduce

  1. git clone git@github.com:sluger/nx-issue-lint-affected.git
  2. npm i
  3. Add any change at https://github.com/sluger/nx-issue-lint-affected/blob/main/apps/react-web-app/src/app/app.spec.tsx#L10
  4. Stage the change git add .
  5. Either git commit to trigger the lint-staged script in: https://github.com/sluger/nx-issue-lint-affected/blob/main/package.json#L57 or just run it directly via npx lint-staged -d

Observed Behavior

$ npx lint-staged -d
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  cwd: undefined,
  debug: true,
  diff: undefined,
  diffFilter: undefined,
  maxArgLength: undefined,
  quiet: false,
  relative: false,
  shell: false,
  stash: true,
  verbose: false
} +0ms
  lint-staged:validateOptions Validating options... +0ms
  lint-staged:validateOptions Validated options! +0ms
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms
  lint-staged:runAll Running all linter scripts... +0ms
  lint-staged:runAll Using working directory `/Users/sluger/git/nx-issue-lint-affected` +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/sluger/git/nx-issue-lint-affected` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +0ms
  lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/Users/sluger/git/nx-issue-lint-affected` +24ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/sluger/git/nx-issue-lint-affected/.git` +0ms
  lint-staged:execGit Running git command [ 'log', '-1' ] +24ms
  lint-staged:execGit Running git command [ 'diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged' ] +14ms
  lint-staged:runAll Loaded list of staged files in git:
  lint-staged:runAll [
  lint-staged:runAll   '/Users/sluger/git/nx-issue-lint-affected/.husky/.gitignore',
  lint-staged:runAll   '/Users/sluger/git/nx-issue-lint-affected/.husky/pre-commit',
  lint-staged:runAll   '/Users/sluger/git/nx-issue-lint-affected/apps/react-web-app/src/app/app.spec.tsx',
  lint-staged:runAll   '/Users/sluger/git/nx-issue-lint-affected/package-lock.json',
  lint-staged:runAll   '/Users/sluger/git/nx-issue-lint-affected/package.json'
  lint-staged:runAll ] +54ms
  lint-staged:searchConfigs Searching for configuration files... +0ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +15ms
  lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +5ms
  lint-staged:searchConfigs Found possible config files: [ '/Users/sluger/git/nx-issue-lint-affected/package.json' ] +20ms
  lint-staged:loadConfig Loading configuration from `/Users/sluger/git/nx-issue-lint-affected/package.json`... +0ms
  lint-staged:loadConfig Successfully loaded config from `/Users/sluger/git/nx-issue-lint-affected/package.json`:
  lint-staged:loadConfig {
  lint-staged:loadConfig   '**/*.{ts,tsx}': [ 'nx affected:test --base=main', 'nx affected:lint --base=main' ]
  lint-staged:loadConfig } +2ms
  lint-staged:validateConfig Validating config from `/Users/sluger/git/nx-issue-lint-affected/package.json`... +0ms
  lint-staged:validateConfig Validated config from `/Users/sluger/git/nx-issue-lint-affected/package.json`: +0ms
  lint-staged:validateConfig {
  lint-staged:validateConfig   '**/*.{ts,tsx}': [ 'nx affected:test --base=main', 'nx affected:lint --base=main' ]
  lint-staged:validateConfig } +2ms
  lint-staged:searchConfigs Found 1 config files +4ms
  lint-staged:groupFilesByConfig Grouping 5 files by 1 configurations +0ms
  lint-staged:chunkFiles Resolved an argument string length of 311 characters from 5 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:generateTasks Generating linter tasks +0ms
  lint-staged:generateTasks Generated task: 
  lint-staged:generateTasks {
  lint-staged:generateTasks   pattern: '**/*.{ts,tsx}',
  lint-staged:generateTasks   commands: [ 'nx affected:test --base=main', 'nx affected:lint --base=main' ],
  lint-staged:generateTasks   fileList: [
  lint-staged:generateTasks     '/Users/sluger/git/nx-issue-lint-affected/apps/react-web-app/src/app/app.spec.tsx'
  lint-staged:generateTasks   ]
  lint-staged:generateTasks } +3ms
  lint-staged:makeCmdTasks Creating listr tasks for commands [ 'nx affected:test --base=main', 'nx affected:lint --base=main' ] +0ms
  lint-staged:resolveTaskFn cmd: nx +0ms
  lint-staged:resolveTaskFn args: [ 'affected:test', '--base=main' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/sluger/git/nx-issue-lint-affected',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:resolveTaskFn cmd: nx +1ms
  lint-staged:resolveTaskFn args: [ 'affected:lint', '--base=main' ] +0ms
  lint-staged:resolveTaskFn execaOptions: {
  cwd: '/Users/sluger/git/nx-issue-lint-affected',
  preferLocal: true,
  reject: false,
  shell: false
} +0ms
  lint-staged:chunkFiles Resolved an argument string length of 80 characters from 1 files +7ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
[STARTED] Preparing lint-staged...
  lint-staged:GitWorkflow Backing up original state... +0ms
  lint-staged:GitWorkflow Getting partially staged files... +0ms
  lint-staged:execGit Running git command [ 'status', '-z' ] +33ms
  lint-staged:GitWorkflow Found partially staged files: [] +16ms
  lint-staged:GitWorkflow Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/sluger/git/nx-issue-lint-affected/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:GitWorkflow Done backing up merge state! +1ms
  lint-staged:GitWorkflow Getting deleted files... +1ms
  lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +18ms
  lint-staged:GitWorkflow Found deleted files: [] +13ms
  lint-staged:execGit Running git command [ 'stash', 'create' ] +13ms
  lint-staged:execGit Running git command [
  'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  '62f9e8558a8ac0684797424031e2c4555f430b4c'
] +25ms
  lint-staged:GitWorkflow Done backing up original state! +40ms
[SUCCESS] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 5 files
[STARTED] **/*.{ts,tsx} — 1 file
[STARTED] nx affected:test --base=main
[SUCCESS] nx affected:test --base=main
[STARTED] nx affected:lint --base=main
[FAILED] nx affected:lint --base=main [FAILED]
[FAILED] nx affected:lint --base=main [FAILED]
[FAILED] nx affected:lint --base=main [FAILED]
[STARTED] Applying modifications from tasks...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
  lint-staged:GitWorkflow Restoring original state... +5s
  lint-staged:execGit Running git command [ 'reset', '--hard', 'HEAD' ] +5s
  lint-staged:execGit Running git command [ 'stash', 'list' ] +26ms
  lint-staged:execGit Running git command [ 'stash', 'apply', '--quiet', '--index', 'refs/stash@{0}' ] +17ms
  lint-staged:GitWorkflow Restoring merge state... +172ms
  lint-staged:GitWorkflow Done restoring merge state! +0ms
  lint-staged:file Removing file `/Users/sluger/git/nx-issue-lint-affected/.git/lint-staged_unstaged.patch` +5s
  lint-staged:file File `/Users/sluger/git/nx-issue-lint-affected/.git/lint-staged_unstaged.patch` doesn't exist, ignoring... +1ms
  lint-staged:GitWorkflow Done restoring original state! +1ms
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up temporary files...
  lint-staged:GitWorkflow Dropping backup stash... +0ms
  lint-staged:execGit Running git command [ 'stash', 'list' ] +130ms
  lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', 'refs/stash@{0}' ] +18ms
  lint-staged:GitWorkflow Done dropping backup stash! +37ms
[SUCCESS] Cleaning up temporary files...

✖ nx affected:lint --base=main:

 >  NX   Running target lint for 2 project(s):

    - react-web-app
    - react-web-app-e2e
   
   With additional flags:
     /Users/sluger/git/nx-issue-lint-affected/apps/react-web-app/src/app/app.spec.tsx

 

> nx run react-web-app:lint /Users/sluger/git/nx-issue-lint-affected/apps/react-web-app/src/app/app.spec.tsx

'_' is not found in schema

> nx run react-web-app-e2e:lint /Users/sluger/git/nx-issue-lint-affected/apps/react-web-app/src/app/app.spec.tsx

'_' is not found in schema

 

 >  NX   Running target "lint" failed

   Failed tasks:
   
   - react-web-app:lint
   - react-web-app-e2e:lint

Running the linter without lint-staged however is successful:

$ npx nx affected:lint --base=main

    ✔  nx run react-web-app-e2e:lint (1s)
    ✔  nx run react-web-app:lint (2s)

 ————————————————————————————————————————————————————————————————

 >  NX   Successfully ran target lint for 2 projects (2s)

I suspect it has something to do with parsing the options of the command via lint-staged. I have accidentally missed a dash on the base option with a similar error message regarding the schema:

$ npx nx affected:lint -base=main

 >  NX   Affected criteria defaulted to --base=main --head=HEAD



    ✖  nx run react-web-app-e2e:lint
       'b' is not found in schema
       

    ✖  nx run react-web-app:lint
       'b' is not found in schema
       

 ————————————————————————————————————————————————————————————————

 >  NX   Ran target lint for 2 projects (185ms)
 
         With additional flags:
           --b=true
           --a=true
           --s=true
           --e=main
 
    ✔    0/2 succeeded [0 read from cache]
 
    ✖    2/2 targets failed, including the following:
         - nx run react-web-app-e2e:lint
         - nx run react-web-app:lint
 

Note I have set NX_VERBOSE_LOGGING=true but it dit not give me any additional output.

Hi @ambeur, @its-ratikant, @jahusa02, @icastillejogomez,

Sorry for the inconvenience. Can one of you create a minimal repro or detailed steps on how can this be reproduced? I tried here https://github.com/meeroslav/test-10768 but I could not reproduce the error.

Additionally, there is no need to set --base=main as this is the default setting when running on your main branch locally.