npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm ls fails if non-module files/directories exist in node_modules directory

this was created over in github a while back, but it doesn’t look like any action was taken on it

My operating system has created an invisible file inside one of my scope’s directories in my global module directory and this causes npm to throw a nasty error (and return non-zero) when trying to get a listing of installed modules.

Specifically, the command I’m running is:

npm ls --global --depth 0
This doesn’t happen when these files live inside the root of the global node_modules directory; only when they’re inside a scope’s directory.

In my opinion, at the least, npm should ignore invisible files in these directories. It appears that it does this for unscoped modules since .DS_Store files in those directories don’t throw any errors. It might also be good if npm would ignore anything that didn’t have a package.json in that directory since it’s not a valid module and should probably just be ignored. But I could see there being value in reporting busted modules in there, perhaps via a --strict flag or similar.

Relatedly, errors also get thrown for broken linked modules (ie: modules that were linked, but the target of the symlinks are no longer valid). I haven’t checked if this failure happens when

How can the CLI team reproduce the problem?

The quickest way to reproduce this problem is to touch a file inside a scope’s directory and run npm ls --global --depth 0 (paths sanitized):

mkdir path/to/global/node_modules/@testscope touch path/to/global/node_modules/@testscop/.DS_Store
$ npm ls --global --depth 0
├── error: ENOTDIR: not a directory, open path/to/global/node_modules/@testscope/.DS_Store/package.json
├── grunt-cli@1.2.0
├── gulp@3.9.1
├── imagemin-cli@1.0.0
├── mime@2.3.1
├── neovim@4.1.0
├── npm@5.7.1
├── standard-version@4.3.0
├── uglify-js@3.4.3
├── vue-cli@2.9.3
└── yo@2.0.3

npm ERR! error in path/to/global/node_modules/@testscope/.DS_Store: ENOTDIR: not a directory, open ‘path/to/global/node_modules/@testscope/.DS_Store/package.json’
supporting information:

npm -v prints: 5.7.1
node -v prints: v8.9.4
npm config get registry prints:

just bumping this to make sure it stays up there and I have to type complete sentences.

I make sure everything gets triaged. I was on vacation in September. Please avoid doing bumps in the future – Discourse is pretty good at keeping things visible, and there’s processes so your thing doesn’t get buried :slight_smile:. Also, please make sure to use the bug template in the future. It makes triage and assessment much easier!

Ah yeah. Sorry about that. When I created the issue I wasn’t sure how this worked. I couldn’t find the bug section and wound up moving it from another category over so wasn’t aware of the template.

Would you like me to edit it up when I’m not on my phone and jam it into the template?

I’ll do better in the future. Thanks!

Go ahead and edit it yourself :slight_smile: