nx icon indicating copy to clipboard operation
nx copied to clipboard

Directories in the .nxignore doesn't prevent nx from scanning them

Open yveskaufmann opened this issue 3 years ago • 4 comments
trafficstars

My situation is that I can't execute any nx run commands because nx scans the whole repository and fails than because it hits a directory in our repository where it is missing the required read permissions. (The mentioned directories are in fact mounted into our database containers. )

Current Behavior

To prevent that I tried to add the mentioned directories to the .nxignore:

.build/**/*
.data/**/*
.data

But nx continued to scan these directories:

$ nx lint 
nx run [project][:target][:configuration] [_..]

Run a target for a project
(e.g., nx run myapp:serve:production).

You can also use the infix notation to run a target:
(e.g., nx serve myapp --configuration=production)

You can skip the use of Nx cache by using the --skip-nx-cache option.

Options:
      --version        Show version number                                                                                                                                                                                                                      [boolean]
      --prod           Use the production configuration                                                                                                                                                                                        [boolean] [default: false]
  -c, --configuration  Target configuration                                                                                                                                                                                                                      [string]
      --project        Target project                                                                                                                                                                                                                            [string]
      --output-style   Defines how Nx emits outputs tasks logs                                                                                                                                               [string] [choices: "dynamic", "static", "stream", "compact"]

Error: EACCES: permission denied, scandir '/home/yves/Documents/Work/dev3/.data/mongodb/diagnostic.data'
    at Object.readdirSync (node:fs:1392:3)
    at readdirWithFileTypes (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.scandir/out/providers/sync.js:16:33)
    at Object.read (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.scandir/out/providers/sync.js:10:16)
    at SyncReader.scandirSync [as _scandir] (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.scandir/out/index.js:18:17)
    at SyncReader._handleDirectory (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.walk/out/readers/sync.js:28:34)
    at SyncReader._handleQueue (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.walk/out/readers/sync.js:23:18)
    at SyncReader.read (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.walk/out/readers/sync.js:15:14)
    at SyncProvider.read (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.walk/out/providers/sync.js:11:29)
    at ReaderSync.walkSync [as _walkSync] (/home/yves/Documents/Work/dev3/node_modules/@nodelib/fs.walk/out/index.js:20:21)
    at ReaderSync.dynamic (/home/yves/Documents/Work/dev3/node_modules/nx/node_modules/fast-glob/out/readers/sync.js:13:21) {
  errno: -13,
  syscall: 'scandir',
  code: 'EACCES',
  path: '/home/yves/Documents/Work/dev3/.data/mongodb/diagnostic.data'

Expected Behavior

I would expect that nx don't scans ignored directories.

Steps to Reproduce

  1. Create a new nx-repository
  2. Create a new directory: mkdir -p .data
  3. Change the owner to another user: chown -R OTHER_USER .data
  4. Remove read-permissions for non owners chmod 600 .data
  5. Add the .data to your .nxignore
  6. Try to invoke any nx run command.

Environment

$ nx report
 >  NX   Report complete - copy this into the issue template

   Node : 16.14.0
   OS   : linux x64
   npm  : 8.3.1
   
   nx : 14.1.4
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : Not Found
   @nrwl/eslint-plugin-nx : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : Not Found
   @nrwl/js : Not Found
   @nrwl/linter : Not Found
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : Not Found
   typescript : 4.3.5
   rxjs : 6.6.0
   ---------------------------------------
   Community plugins:

yveskaufmann avatar May 11 '22 12:05 yveskaufmann

We are experiencing this problem as well. @yveskaufmann Did you find any workaround for the moment?

bjoernWahle avatar May 31 '22 15:05 bjoernWahle

Same problem here...

savvyshell avatar Jun 20 '22 23:06 savvyshell

+1

stefanholzapfel avatar Jun 22 '22 15:06 stefanholzapfel

+1

hoevelmanns avatar Sep 21 '22 00:09 hoevelmanns

@bjoernWahle The solution for me was to move the mounted directories out of the repository.

yveskaufmann avatar Sep 27 '22 16:09 yveskaufmann

getting this issue too, moving the mounted directories out of the repository is not really a solution in my case.

dustyhorizon avatar Oct 31 '22 10:10 dustyhorizon

seems like the code at https://github.com/nrwl/nx/blob/d2bec05e6caa2f23cebdf021b6988c7ae3c1df8d/packages/nx/src/config/workspaces.ts#L715 causes this; using the original projectGlobPatterns array and adding negative glob patterns to it seems to do the trick, probably have to write a small patch to load ignores from .nxignore and adding it to the ignore parameter of the globSync fn

... or we could just add suppressErrors: true to globSync

dustyhorizon avatar Oct 31 '22 20:10 dustyhorizon

same issue. any solution yet?

AdhamMoussa avatar Jan 21 '23 18:01 AdhamMoussa

This has been fixed

AgentEnder avatar Feb 27 '23 20:02 AgentEnder

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[bot] avatar Mar 30 '23 00:03 github-actions[bot]