"Cannot read property 'match' of undefined" during Npm install - node.js

I encountered error during building Jenkins
Jenkins Log
Task :api:processResources
Task :api:classes
Task :web:nodeSetup
Task :web:npmSetup /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npm
-> /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/lib/node_modules/npm/bin/npm-cli.js
/var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npx
-> /var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/lib/node_modules/npm/bin/npx-cli.js
npm#6.11.2 added 430 packages from 832 contributors in 6.837s
Task :web:npmInstall FAILED npm ERR! Cannot read property 'match' of undefined
npm ERR! A complete log of this run can be found in: npm ERR!
/var/lib/jenkins/.npm/_logs/2019-10-16T01_11_20_594Z-debug.log
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':web:npmInstall'.
Process 'command '/var/lib/jenkins/workspace/hds_v2_docker/web/.gradle/npm/npm-v6.11.2/bin/npm''
finished with non-zero exit value 1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 6.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 33s
/var/lib/jenkins/.npm/_logs/2019-10-16T01_11_20_594Z-debug.log
17 silly saveTree │ ├─┬ clean-css#4.2.1
17 silly saveTree │ │ └── source-map#0.6.1
17 silly saveTree │ ├── commander#2.17.1
17 silly saveTree │ └── he#1.2.0
17 silly saveTree └─┬ loader-utils#0.2.17
17 silly saveTree ├── big.js#3.2.0
17 silly saveTree ├── emojis-list#2.1.0
17 silly saveTree └── json5#0.5.1
18 verbose stack TypeError: Cannot read property 'match' of undefined
18 verbose stack at tarballToVersion (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:87:20)
18 verbose stack at inflatableChild (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:99:22)
18 verbose stack at BB.each (/usr/local/lib/node_modules/npm/lib/install/inflate-shrinkwrap.js:55:12)
18 verbose stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18 verbose stack at Object.gotValue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:155:18)
18 verbose stack at Object.gotAccum (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/reduce.js:144:25)
18 verbose stack at Object.tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18 verbose stack at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
18 verbose stack at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
18 verbose stack at Promise._settlePromiseCtx (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:606:10)
18 verbose stack at _drainQueueStep (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:142:12)
18 verbose stack at _drainQueue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:131:9)
18 verbose stack at Async._drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:147:5)
18 verbose stack at Immediate.Async.drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
18 verbose stack at runCallback (timers.js:810:20)
18 verbose stack at tryOnImmediate (timers.js:768:5)
19 verbose cwd /var/lib/jenkins/workspace/hds_v2_docker/web
20 verbose Linux 4.4.0-59-generic
21 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "install"
22 verbose node v8.16.0
23 verbose npm v6.9.0
24 error Cannot read property 'match' of undefined
25 verbose exit [ 1, true ]

Try removing your package-lock.json to see if that helps.
rm -rf package-lock.json
Edit: If the issue still persists, delete node_modules as well.
rm -rf node_modules

You have to remove both package-lock.json and node_modules/.
If you don't remove both, the problem will come back on the next npm install.

I had the same error when running npm install in my repo. I don't use Jenkins, but I found a generic approach to debugging (and ultimately resolving) this issue in NPM.
Open the npm debug log file that the cli provides you. (on Windows, under C:\Users\USERNAME\AppData\Roaming\npm-cache\_logs by default)
Look for the stack trace of the error, at the bottom of the file.
The first three lines of the error stack trace should be something like:
18 verbose stack TypeError: Cannot read property 'match' of undefined
18 verbose stack at tarballToVersion (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:87:20)
18 verbose stack at inflatableChild (C:\Users\USERNAME\AppData\Roaming\nvm\v14.5.0\node_modules\npm\lib\install\inflate-shrinkwrap.js:113:22)
Open up the inflate-shrinkwrap.js file, and go to the line listed in stack-trace line #3 above.
Add this debugging code: (just before the line [in stack-trace] which calls tarballToVersion)
if (sw.version == null) {
console.error(`
NPM is trying to retrieve package "${name}" with version "undefined"!
Package location: ${(onDiskChild || {}).location}
Package parse error:`, (onDiskChild || {}).error);
}
Run npm install (or whatever command yields the error). You should see an output like this:
NPM is trying to retrieve package with version "undefined"!
Package location: /firebase-feedback/webpack-dev-middleware
Package parse error: [Error: ENOENT: no such file or directory, open 'C:\Root\Apps\#V\#Modules\firebase-feedback\Main\node_modules\webpack-dev-middleware\package.json'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Root\\Apps\\#V\\#Modules\\firebase-feedback\\Main\\node_modules\\webpack-dev-middleware\\package.json'
}
Go to the path specified in the internal error. You should find that the package.json file at that path is indeed missing.
Resolve that underlying "package.json" issue as you see fit. (for me, this was by deleting the C:/Root/Apps/#V/#Modules/firebase-feedback/Main/node_modules folder, then running npm install in the Main folder)
Note that in my case, the underlying issue (of the missing package.json file) appears to have been caused by me accidentally running npm install from the parent project (which uses my firebase-feedback library), while I had that library "npm linked".
I normally use npm-safe-install to avoid these sorts of issues (when using npm link), but I must have forgotten sometime recently -- leading to NPM mangling the npm-linked libraries' node_modules folders.
Similar issues relating to npm link have happened before, but I hoped NPM would have patched these sorts of issues by now. Apparently not; though version 7 of NPM has been stated as going to have a rewrite in that area, so hopefully that will solve it long term.

You have to remove project Package-lock.json file. then try to install what you want.

The error may vary on what npm internals file it can be thrown! (And i wonder for all the possible reasons)! And it should be a bug!
(in my last case: it was on [_canPlaceDep] method of the file build-ideal-tree.js of npm!
Note
If none of the common methods works! And that you are using nodejs v15+ and one of latest npm version! Go to the last part! The problem that i call the nodejs VERSIONS HELL! (NOTE: after reflection! For npm it may not be a version HELL! READ TO KNOW)
How to try to solve
Removing node_modules
\rm -r node_modules
Reinstall after
npm install
(NOTICE: that may still not work)
You can try to remove package.lock too!
Clearing the cache
npm cache clean --force
That can work if the cache get currupted somehow! But the common error is more of Unexpected end of JSON input while parsing near ...
You can check my answer here (that explain it well): https://stackoverflow.com/a/52249619/7668448
Removing package.lock (which is not adviced)
rm package.lock
Why not advised
From #DanielIM comment
No, it should not. This is "the recommended workaround" but is incredibly broken in practice. Having a locked dependency in package.json in no way ensures that dependency's dependencies will remain consistent, so removing the package-lock.json file, npm installing, and generating a newlock file *will allow those sub-dependencies to change, which often completely breaks any future building. Using an existing lock file is often the only way to maintain builds (that is the POINT of the file, after all) so removing it completely goes against the reason for its existence.
So generally it's nice to leave that as a last resort! If it does not work ! You can try with removing node_modules too!
Reinstalling nodejs or NPM
A problem can happen at npm level! Trying to reinstall can be a nice way!
To test quickly in place of reinstalling! Using NVM (nodejs version manager) and switching to another version is fast and interesting! Because we can also test for VERSION HELL PROBLEM!
If it works after switch! Then either it's a problem with npm and a reinstallation may fix it! Or it's a version Hell problem (a bug)!
How to reinstall fast! Again use nvm!
nvm uninstall v15
then
nvm install v15
then use it
nvm use v15
You can just install another version and use it! (v14 for example)
Check the VERSION HELL PROBLEM And how to use nvm to switch between versions!
The uncommon or new! THE VERSIONS HELL
In this year! I encountered many nodejs VERSIONS HELL problems! (I like to call them that) (because i gave them a name! The skies are blessing me with more) (irony)
To list them quickly:
Node v14 HELL (POSTGRES) and causing problem for pg module (postgres) [because of breaking changes! That pg was depending on!] (if you are using knex or any orm or query builder! And use it with postgres! Big chance you'll encounter it! If you just upgrade nodejs version alone! [Solution: upgrade pg versoin to the latest (>=8.0.3) [They made a fix] (Can check a full detailed explanation here https://stackoverflow.com/a/64639717/7668448)]
Typescript v4 HELL! A similar problem! Where typescript in one of my project fail internally with cannot read property "" of undefined! Rolling back to v3.9 run successfully! No problem!
Fix Our problem (Cannot read property 'matches' of undefined)
If you are using node v15! Try with node v14 (npm v6.14.8)! That may be it! An npm bug! That's a first thought can be! That what i thought at first!
That's was the case for me! In this last problem! I tried all the solutions that i'm familiar with! And they were already listed here too! None worked! And more when i removed node_modules! I was Please not another version HELL! And yea it was exactly that! It worked well with **node v14** (npm v6.14.8). Which suggest a [BUG].
Then reflecting a bit on it! It was like hey! When i change the version! I'm using another nodejs installation! Which can just not have the problem. A problem with npm structure or something and a re-installation may fix it (as mentioned above)!
After it ! I tried with node v15.3.0. And it worked all ok! After the installation was all right done! I went back to node v15.0.1! And it worked again! So the problem is absolutely not a VERSION HELL problem
I'm still uncapable to explain what did happen! But in short! Using NVM! To try with another version! Is a good way to go about it! You can reinstall quickly the current version too!
Big Take down (for the VERSION HELL)
Starting from nodejs v14! And v15! Or just generally! It's nice to be skeptical about the versions! More of a reason when it doesn't make sense! And that's about all the problems not just npm! There is so many VERSIONS HELL problems! I encountred 2 up to now! Being alerted to the VERSIONS HELL can save you a lot of time!
How to test fast and also switch nodejs version quickly
To be fast at testing this and checking! Mostly for any internal error that will come! I'll google it quickly! And try another version of nodejs or whatever in question (ex: typescript)! I can too debug (console.log) The internal file where the error was thrown! And try to figure out something!
But that's it! It's really interesting to check for other versions! (nodejs, typescript, ... [remember be skeptical or alerted])
For nodejs To do it quickly:
NVM to switch quickly nodejs versions (npm)
Use NVM (nvm is a version manager for node.js,)
Quick installation of version in NVM
nvm install v14
Quick switch to another node version
nvm use v14
(Check the doc for the details! And installation process)
For switching and testing some npm module version (ex: typescript)
If it's a cli tool! you can install a precise version globaly
npm i -g typescript#3.9
use the # syntax!
Once you verify and test you can switch back to whatever you like!
If it's in a project! You can do the same (not globally)! use the # syntax to precise the version!
npm i moduleName#<versionSpecifier>
or with saving
npm i moduleName#<versionSpecifier> --save
Version specifier use SEMVER convention (https://semver.org/).
Last tip (use npx in your scripts)
It's nice to set a version internal to the project! For example
"devDependencies": {
"#types/cors": "^2.8.6",
"#types/gulp": "^4.0.6",
"cross-env": "^6.0.3",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"nodemon": "^2.0.4",
"ts-node": "^8.10.2",
"typescript": "^3.9.7", // <===== Typescript version 3.9 (for this project)
"jest": "^26.6.3"
}
In scripts i use npx:
"scripts": {
"build": "npx tsc && gulp build",
When we use npx this way with a nodjes module cli tool! npx will check first if the module is available in the local node_modules! If found will use it (use global otherwise, or Download latest and run)!
So doing what i'm suggesting! Will make sure your project will run independently from whatever you have in global!
(Read more about npx if you don't know the tool well)

Following steps work for me -
Delete npm and npm catch folder from ../AppData/Roaming
Install latest node js for here.
Retry all the steps according to your repo.

Related

How to publish [my own] npm package that can be invoked globally

I've published a new public node app via npm. (Note: This is clearly an alpha. Don't expect very good, much less perfection.) I'm unable to get it work as a global install.
https://www.npmjs.com/package/khutzpa
To test, I installed it globally with this:
npm install -g khutzpa
On macOS, that installs in /usr/local/lib/node_modules/khutzpa for me.
I expected to be able to execute it at this point from the command line like this:
khutzpa /usr/local/lib/node_modules/khutzpa/tests/fakeSite /openInBrowser
I cannot. When I run that line, I receive:
zsh: command not found: khutzpa
I have other packages installed globally that are found, including prettier and eslint.
If I run it via a full path to its index.js, it's happy and runs exactly like I'd expect.
node /usr/local/lib/node_modules/khutzpa/index.js /usr/local/lib/node_modules/khutzpa/tests/fakeSite /openInBrowser
That's the basic issue. Is there something additional I'm supposed to set up?
More info
index.js
I think all I need in package.json is the main entry, and I have that...
"main": "index.js",
You can see the index.js file in full here.
In that file, I'm doing a if (require.main === module) { check to see if it's used as a module, which might be an issue now (?), but that doesn't seem to explain why it's not found at all.
npx
If I run with...
npx khutzpa /usr/local/lib/node_modules/khutzpa/tests/fakeSite /openInBrowser
I receive...
npm ERR! could not determine executable to run
There's not a lot more info in the log it creates afaict.
34 verbose stack Error: could not determine executable to run
34 verbose stack at getBinFromManifest (/usr/local/lib/node_modules/npm/node_modules/libnpmexec/lib/get-bin-from-manifest.js:17:23)
34 verbose stack at exec (/usr/local/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:114:15)
34 verbose stack at async module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:66:5)
35 verbose pkgid khutzpa#0.0.1-alpha
36 verbose cwd /usr/local/lib/node_modules/prettier
37 verbose Darwin 21.5.0
38 verbose argv "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "exec" "--" "khutzpa" "/usr/local/lib/node_modules/khutzpa/tests/fakeSite" "/openInBrowser"
39 verbose node v16.15.0
40 verbose npm v8.5.5
41 error could not determine executable to run
42 verbose exit 1
as a require in another package
Just tried invoking as an include, and it seems to work okay, except that I have to use khutzpa.default to invoke it, which I didn't think I needed to do. Maybe a hint. I'mma googling.
But I...
Created a dir.
npm init -y
On command line in that dir ran npm install khutzpa
Inserted this code:
const khutzpa = require("khutzpa");
console.log(khutzpa);
khutzpa.default("/usr/local/lib/node_modules/khutzpa/tests/fakeSite", 3000, 1);
That works, though khutzpa("/usr/local/lib/node_modules/khutzpa/tests/fakeSite", 3000, 1); does not, so maybe an export issue?
Looks like there may have been two issues:
I needed a "sharp-exclamation" in my index.js file to let npm know where node is (?).
I needed a "bin" entry in package.json.
The best way to sum this is probably by pointing at this commit that fixed things.
Here's a summary in an image with a reasonably good alt description, I believe. I'll add some WinMerge reports in a bit:

Failure with `builtins` while publishing to NPM

I have this failure trying to publish a package
npm ERR! builtins is not a function
Which comes from
37 verbose stack TypeError: builtins is not a function
37 verbose stack at validate (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/node_modules/validate-npm-package-name/lib/index.js:55:3)
37 verbose stack at Result.setName (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/node_modules/npm-package-arg/lib/npa.js:127:17)
37 verbose stack at new Result (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/node_modules/npm-package-arg/lib/npa.js:119:10)
37 verbose stack at Function.resolve (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/node_modules/npm-package-arg/lib/npa.js:56:15)
37 verbose stack at npa (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/node_modules/npm-package-arg/lib/npa.js:26:18)
37 verbose stack at Function.pickRegistry (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/node_modules/npm-registry-fetch/lib/index.js:189:10)
37 verbose stack at Publish.exec (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/lib/commands/publish.js:107:33)
37 verbose stack at async module.exports (/home/runner/work/typeorm-seeding/typeorm-seeding/node_modules/npm/lib/cli.js:66:5)
Does someone have any idea? I could not found any info about this error.
Greetings!
Just in case someone else comes across this, I had the same exact issue (first time using node.js on a Windows machine). Not much out there that speaks to this problem, so the fix for me was to completely un-install Node - then reinstall it.
Then, this error went away.
I recently faced this problem and was stuck with this for three days.
With me, all my "node" and "npm" were up to date but all the commands with npm apart from the version check ie "npm -v" was giving me more or less the same error "builtins is not a function".
sol 1 - One can try to uninstall node and npm and then re-install from the fresh.
If that doesn't solve the problem and you are still getting the same error then try the next solution
sol 2 - Install yarn https://phoenixnap.com/kb/yarn-windows
Use yarn commands instead of "npm". The following link will help you find all the yarn commands equivalent to npm commands.
https://www.sitepoint.com/yarn-vs-npm/

Starting application using node works but not yarn or npm

There is probably an obvious answer to someone who is more familiar with NodeJS than me but:
When running an application which is using a node-gyp package, it runs without problems using
node ./src/index.js
However running it using a very simple package.json start-script:
"scripts": {
"start": "node ./src/index.js"
}
in npm:
npm start
npm info it worked if it ends with ok
npm info using npm#6.9.0
npm info using node#v11.10.1
npm info lifecycle rosbag2#0.1.0~prestart: rosbag2#0.1.0
npm info lifecycle rosbag2#0.1.0~start: rosbag2#0.1.0
> rosbag2#0.1.0 start /Users/andreasklintberg/personal/xviz/examples/converters/rosbag2
> node ./src/index.js "./src/index.js"
internal/modules/cjs/loader.js:779
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: dlopen(/Users/andreasklintberg/personal/xviz/examples/converters/rosbag2/node_modules/rosbags2_nodejs/build/Release/rosbags2_nodejs.node, 1): Library not loaded: #rpath/librosidl_typesupport_cpp.dylib
Referenced from: /Users/andreasklintberg/personal/xviz/examples/converters/rosbag2/node_modules/rosbags2_nodejs/build/Release/rosbags2_nodejs.node
Reason: image not found
And similarly in yarn
yarn start
yarn run v1.13.0
warning package.json: No license field
$ node ./src/index.js ./src/index.js -d ../../../data/rosbag2/rosbag2_2019_03_09-21_54_44 -o ../../xviz-data/rosbag2/rosbag2_2019_03_09-21_54_44/
internal/modules/cjs/loader.js:779
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: dlopen(/Users/andreasklintberg/personal/xviz/examples/converters/rosbag2/node_modules/rosbags2_nodejs/build/Release/rosbags2_nodejs.node, 1): Library not loaded: #rpath/librosidl_typesupport_cpp.dylib
Referenced from: /Users/andreasklintberg/personal/xviz/examples/converters/rosbag2/node_modules/rosbags2_nodejs/build/Release/rosbags2_nodejs.node
Reason: image not found
I know the error is because a dynamic link/#rpath is messed up, and I was thinking it was because npm/yarn messes with the env variables or something, but running yarn env it seems everything is correct.
So I guess i'm wondering if anyone know what the difference is running it in native node and using npm/yarnscript to wrap the start? And why this difference messes up the #rpath/dynamic linking ?
Edit:
My index.js file is very simple, just imports the built node-gyp package:
let RosbagDeserializer = require('../build/Release/rosbags2_nodejs.node');
const deserializer = new RosbagDeserializer.Rosbag2Wrapper();
This is the project in question, https://github.com/klintan/rosbag2_nodejs
I would love a more comprehensive answer but at least I solved it with the help of a lot of wonderful commenters:
The #rpath is not set on Mac, but with DYLD_LIBRARY_PATH it works, because that is one of the runtime search paths, it seems (https://superuser.com/questions/282450/where-do-i-set-dyld-library-path-on-mac-os-x-and-is-it-a-good-idea). However for some reason NPM removes this, I'm guessing it has to do with SIP on Mac, or maybe some other security measure that removes this env variable.
DYLD_LIBRARY_PATH is available if you run node index.js but NOT if you are running it using npm start (node index.js start script).
Both #Michal Kapracki and #Avik was hinting at this (I missed the missing env variables when comparing the first time)
What I did to solve it was similar to the dyld: Library not loaded ... Reason: Image not found question as #Avik linked, I had to add a bunch of libraries which were dependent (that was automatically resolved before) and a post_install.sh script which uses the install_name_tool to change the #rpaths to the correct path.
It's a pretty ugly solution https://github.com/klintan/rosbag2_nodejs/blob/master/post_install.sh but it works.
Only for Mac though, so needs to be generalized.
So in summary what I think is the issue:
NPM for some reason can't use or removes the env variable DYLD_LIBRARY_PATH which is used to search for dynamically linked libraries during runtime. This makes it necessary to link these manually using the mac tool install_name_tool.

NPM stuck giving the same error EISDIR: Illegal operation on a directory, read at error (native)

I am stuck with this error no matter what directory I am in, and what I type after "npm" in cmd.exe. Here is the npm-debug.log:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js' ]
2 info using npm#2.14.12
3 info using node#v4.2.6
4 verbose stack Error: EISDIR: illegal operation on a directory, read
4 verbose stack at Error (native)
5 verbose cwd C:\Users\me
6 error Windows_NT 6.1.7601
7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
8 error node v4.2.6
9 error npm v2.14.12
10 error code EISDIR
11 error errno -4068
12 error syscall read
13 error eisdir EISDIR: illegal operation on a directory, read
13 error eisdir This is most likely not a problem with npm itself
13 error eisdir and is related to npm not being able to find a package.json in
13 error eisdir a package you are trying to install.
14 verbose exit [ -4068, true ]
I have tried and uninstalling/reinstalling nodejs multiple times, I even deleted npm and npm-cache folders in C:\Users\me\AppData\Roaming. I'm not sure what went wrong to cause this. One second it was working fine, and now I can't get rid of this error. The explanation in the log does not make sense, as it gives this error in any directory. I should note that running a command prompt as administrator does not give this error. I'm pulling my hair out this Friday evening trying to get this fixed, any help would be greatly appreciated!
EISDIR stands for "Error, Is Directory". This means that NPM is trying to do something to a file but it is a directory. In your case, NPM is trying to "read" a file which is a directory (Line: 4). Since the operation cannot be done the error is thrown.
Three things to make sure here.
Make sure the file exists. If it does not, you need to create it. (If NPM depends on any specific information in the file, you will need to have that information there).
Make sure it is in fact a file and not a directory.
It has the right permissions. You can change the file to have all permissions with "sudo chmod 777 FILE_NAME". (Careful: You are giving Read, Write and Execute permissions to every one on that file)
I ran into the same problem while I was changing some npm settings. I did a mistake with one npm config set command and this added a line referring to a non-existing directory to C:\Users\{User}\.npmrc. After I deleted that line manually from .npmrc, the problem was gone.
In my case I was getting the "EISDIR: illegal operation on a directory, read" because in my .angular-cli.json file I wasn't providing a full path in "scripts:"
For example I had
"scripts": [
"../node_modules/hammerjs",
"../node_modules/moment"
],
In fact it should have been
"scripts": [
"../node_modules/hammerjs/hammer.min.js",
"../node_modules/moment/min/moment.min.js"
],
Had the same problem today after i've upgraded my npm from version 6.4.1 to version 6.5.0. I fixed this by downloading the .pkg installer (recommended for most users) from node.js and runned it afterwards.
I had the same issue on Mac OS X (installed with homebrew), and the .npmrc is not the only place node stored config variables. There is a glocal npmrc config file in /usr/local/etc that you have to edit using this command:
sudo nano npmrc
Remove the ca= line, or whatever the config setting was that broke your install, save that file, and try npm again, and you should see it working.
These strange errors occured recently on my OSX machine.
I could help myself the quick & dirty way by running:
sudo chmod -R 777 /usr/local/lib/node_modules/
Something seemed to have messed up the access rights of all global node modules.
For me it was because I was using the the wrong path; it should have been a path to a file yet I was wrongly using a path to a directory:
Changed this:
path.resolve(__dirname, '../');
Into this:
path.resolve(__dirname, '../.env')
So most of the answers were saying it was related to the .npmrc file.
In my case, I was deploying a serverless application using serverless deploy and the message
EISDIR: illegal operation on a directory, unlink '/home/malvadao/workspace/project/.build/node_modules'
was being thrown.
Deleting the .build folder did it for me. It was the folder generated after Typescript compilation. Since the folder is recreated after launching the serverless deploy command, it was enough to solve the problem and continue the flow.
In other words, manually deleting the folder might be enough for you to move forward, without the need to touch .npmrc
If your problem is associated with the React Native packager. Try resetting the cache with react-native start --reset-cache.
For me fixing was add slash after directory name
Make sure node_modules (and your root package.json) doesn't contain a reference to npm's "package.json" module. Deleting package.json FOLDER from node_modules solved the issue for me.
Just delete .npmrc folder in c:users>'username' and try running the command it will be resolved !
Doing a complete uninstall, including removing paths, etc and reinstalling has solved the problem, very strange problem though.
How to completely remove node.js from Windows
I had this issue with gulp. The problem was that gulp added a dependency to my source file and I think npm tried to open it:
{
"name": "name",
"version": "2.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"appname": "file://gulp",
"gulp-concat": "^2.6.1",
"gulp-electron": "^0.1.3",
"gulp-shell": "^0.5.2",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.7",
"node-7z": "^0.4.0"
}
}
Make sure that there are no strange references in you package.json file.
Check to ensure you are running npm install from the proper directory.
(The package.json file could be one extra directory down, for example.)
Had the same problem until I tried deleting the .git folder. It worked. I guess this type of problem can have different causes.
In my case I forgot to pass the full path of one of the file it was asking. After passing full path of the file worked :)
In my case, i was facing this issue while installing create-react-app in MAC (Mojave OS) with following command :
sudo npm install create-react-app -g
and got errors like this :
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/scheduler'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/webSocket'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/webSocket'
I have read npm.community that try to install without sudo :
npm install create-react-app -g
and it actually solved my issue ..!!
I had the same problem.
Recently just deleted the .npmrc file in the user directory and afterwards, I ran npm init -y
Works!
In my case, my fault was assuming, that script allow to work with directories, but it waited FILE PATH, so try to set full path to file.
In my case was:
['/var/task/myFolder']
but right path should be :
['/var/task/myFolder/sample.tgs']
Project related to chromium usage inside puppeteer on serverless was lambda. Hope, it helps.
I had a similar problem while setting up boilerplate code. It was reading my bundle.js file as a directory. So as stated here. EISDIR mean its a directory and not a file. To fix the issue, I deleted the file and just recreated (it was originally created automatically).
If you cannot find the file (because its hidden), simply use the terminal to find and delete it.
I had the same issue. There was a linked folder in my directory which was causing the issue. i added that folder to ignore list and then it started working fine as expected.
I know this isn't specifically asking about forever js.. but google lead me here so.. For me it was as simple as an ending slash.
I just changed:
forever start -a -l /dev/null/ /var/www/node/my_file.js
To:
forever start -a -l /dev/null /var/www/node/my_file.js
And the error disappeared
Make sure to check your version of npm and whether or not there are issues with it. I was having the same issue at the time of this post and I discovered that my npm version (6.5) was having issues. I had to uninstall and reinstall npm version 6.4.1 and then everything started to work great again.
I had a broken symlink to node_modules in a subfolder
In my case, I'm using Windows 10 in Spanish and this version mixes English and Spanish directory names. My problem was that the desktop directory has this name for some commands and escritorio to others. I believe that npm cannot resolve this. My solution was to simply change to another directory starting from C:\ different to my home directory.
I had faced similar issue. I set cafile using the command:
npm config set cafile PATH_TO_CERTIFICATE
I was able to resolve this by deleting the certificate file settings, and setting strict-ssl = false.
I fixed this issue by moving my directory from my exFAT drive which does not support symlinking.
My exFat drive is shared between osx and a bootcamp windows partition so when I tried to clone and npm install my project it was failing but never explains that exFAT doesn't support this functionality.
There are drivers out there that you can install to add the ability to symlink but you'll have to do a lot of your setup manually compared to running a simple npm script.
For mac os:
If installed directly from nodejs website the npmrc file would be located in /usr/local/etc/npmrc. Just delete the config which is undefined and this problem would be fixed.
In my case, the C:\Users\{user}\AppData\local\npm files were hidden, so I was not able to find & delete the trouble directory. Took me DAYS to realize this!
So double check to un-hide any folders so you don't miss them! Here's a link to do this if you don't know how.

Node app fails to run because of prerelease

I get invalid packages installing, even if the installation is a success. Btw, this question is related to the answer - question about versioning
npm install serialport
These are packages which is stuck far in the dependency tree.
npm ERR! invalid: readable-stream#1.0.27-1 /Users/snorre edwin/Code/raspberry-node-server/node_modules/serialport/node_modules/node-pre-gyp/node_modules/tar-pack/node_modules/readable-stream
npm ERR! invalid: string_decoder#0.10.25-1 /Users/snorre edwin/Code/raspberry-node-server/node_modules/serialport/node_modules/node-pre-gyp/node_modules/tar-pack/node_modules/readable-stream/node_modules/string_decoder
This ends up causing this error in my browser:
Uncaught TypeError: Cannot read property '_ansicursor' of undefined
Is there any way to sort up in this npm problem? Can I avoid these prerelease packages?
The github answere below gave me a lot of insight into npm and I thought I had to dig somewhere else for the issue. But it acctually just seemed like serialport does not work very well, anymore, with browserify. It used to work because i used if for two months, but something changed. When im saying it out loud, it just sounds stupid anyway. So dont browserify serialport.
I recieved an answere on github, issue answere, thought i would share it with the rest who might wonder:
The change in handling prerelease versions in semver#4 is one of the primary motivators for the major version bump to npm#2. All versions of npm 2 are affected by this change, which, put briefly, ensures that all version information to the right of - in version strings is ignored when doing semver range matching. When you upgrade from npm#1 to npm#2, it's normal to see some irregularities show up when you run npm -g ls, and since some packages are distributed as self-contained installs via the use of bundledDependencies, they may come out of the package in a state that is inconsistent with npm#2's rules.
While this won't always work, most of the time the easiest way to fix these issues is simply to uninstall and reinstall the affected package. For packages that ship with bundledDependencies, if you really want to get everything cleaned up, you can cd into the node_modules folder containing the version of the package with the noisy prerelease dependency version and just run npm install problemDependency, and it will use the newest version of that dependency that matches the semver range for that particular package.
Re: your second question, semver range checking is done semantically, not lexically, so 1.0.31 should match with npm#2:
% semver -r '~1.0.2' 1.0.26 1.0.27-1 1.0.31
1.0.26
1.0.31
I suspect that the behavior you're seeing is due to a bundledDependency included in the package tarball.
All of this is documented, so I'm going to close this issue. I hope this clears things up for you!

Resources