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)
I’m opening this issue because:
- npm is crashing.
- npm is producing an incorrect install.
- npm is doing something I don’t understand.
- npm is producing incorrect or undesirable behavior.
- Other (see below for feature requests):
What’s going wrong?
D:MyDevljs_apptrunkperiscopebuild>npm i
npm ERR! Cannot read property ‘match’ of undefined
2018-06-11T07_39_39_234Z-debug.log
When removing the package-lock.json
file the installation works again.
How can the CLI team reproduce the problem?
Run npm i with the attached files
x.zip
configuration files:
supporting information:
npm -v
prints: 6.1.0node -v
prints: 10.4.0npm config get registry
prints: http://registry.npmjs.org/- Windows, OS X/macOS, or Linux?: Windows
- Network issues:
- Geographic location where npm was run:
- I use a proxy to connect to the npm registry.
- I use a proxy to connect to the web.
- I use a proxy when downloading Git repos.
- I access the npm registry via a VPN
- I don’t use a proxy, but have limited or unreliable internet access.
- Container:
- I develop using Vagrant on Windows.
- I develop using Vagrant on OS X or Linux.
- I develop / deploy using Docker.
- I deploy to a PaaS (Triton, Heroku).
When trying to run an npm
command, you can’t install the packages, you may get the error:
stephen ~/_coding/remine/revolution master 👉 npm run setup
> revolution@0.0.1 setup /Users/stephen/_coding/remine/revolution
> lerna link && lerna bootstrap
lerna notice cli v3.15.0
lerna info Symlinking packages and binaries
lerna notice cli v3.15.0
lerna info Bootstrapping 6 packages
lerna info Installing external dependencies
lerna ERR! npm install exited 1 in '@revolution/web'
lerna ERR! npm install stderr:
npm ERR! Cannot read property 'match' of undefined
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/stephen/.npm/_logs/2019-10-11T17_31_46_811Z-debug.log
lerna ERR! npm install exited 1 in '@revolution/web'
lerna WARN complete Waiting for 5 child processes to exit. CTRL-C to exit immediately.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! revolution@0.0.1 setup: `lerna link && lerna bootstrap`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the revolution@0.0.1 setup script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/stephen/.npm/_logs/2019-10-11T17_31_46_935Z-debug.log
Enter fullscreen mode
Exit fullscreen mode
While not a root-cause solution, a workaround is:
- Delete
node_modules
andpackage-lock.json
- Run
npm install
again
An Animated Guide to Node.js Event Lop
Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.
What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.
verbose stack TypeError: Cannot read property 'match' of undefined
18 verbose stack at tarballToVersion (C:UsersadminAppDataRoamingnpmnode_modulesnpmlibinstallinflate-shrinkwrap.js:87:20)
18 verbose stack at inflatableChild (C:UsersadminAppDataRoamingnpmnode_modulesnpmlibinstallinflate-shrinkwrap.js:99:22)
18 verbose stack at BB.each (C:UsersadminAppDataRoamingnpmnode_modulesnpmlibinstallinflate-shrinkwrap.js:55:12)
18 verbose stack at tryCatcher (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseutil.js:16:23)
18 verbose stack at Object.gotValue (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleasereduce.js:155:18)
18 verbose stack at Object.gotAccum (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleasereduce.js:144:25)
18 verbose stack at Object.tryCatcher (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseutil.js:16:23)
18 verbose stack at Promise._settlePromiseFromHandler (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleasepromise.js:517:31)
18 verbose stack at Promise._settlePromise (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleasepromise.js:574:18)
18 verbose stack at Promise._settlePromiseCtx (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleasepromise.js:611:10)
18 verbose stack at _drainQueueStep (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseasync.js:142:12)
18 verbose stack at _drainQueue (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseasync.js:131:9)
18 verbose stack at Async._drainQueues (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseasync.js:147:5)
18 verbose stack at Immediate.Async.drainQueues [as _onImmediate] (C:UsersadminAppDataRoamingnpmnode_modulesnpmnode_modulesbluebirdjsreleaseasync.js:17:14)
18 verbose stack at runCallback (timers.js:705:18)
18 verbose stack at tryOnImmediate (timers.js:676:5)
19 verbose cwd C:UsersadminDesktopprojectsreact-template-three
20 verbose Windows_NT 6.3.9600
21 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\admin\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install" "--save" "google-map-react"
22 verbose node v10.16.3
23 verbose npm v6.13.1
24 error Cannot read property 'match' of undefined
25 verbose exit [ 1, true ]
I tried doing: npm install —save google-map-react
Issue
Running an npm command, such as npm install
or npm ci
, may raise something like this:
npm err TypeError: Cannot read property 'match' of undefined
and break the script that is running.
Resolution
This is a known version bug in NPM. Right now, the best way to resolve is to regenerate the package-lock.json
until there is a fix for the cause.
-
Remove the
node_modules
andpackage-lock.json
(ornpm-shrinkwrap.json
, if that is what is being used). (rm package-lock.json && rm -rf node_modules
) -
Check the local versions of Node and npm.
node -v
npm -v
-
If the Node and npm versions locally don’t match the
"engines"
in thepackage.json
, install the versions that match thepackage.json
. For information on installing Node and npm locally, visit the Node docs: https://nodejs.org/en/download/ -
Regenerate the
package-lock.json
. Do this by runningnpm install
. Thenode_modules
will also be regenerated.
Ask on Stack Overflow
Engage with a community of passionate experts to get the answers you need
Ask on Stack Overflow
0
{{postValue.vote_count}}
Hello,While installing the package using npm,I have got the error that says cannot read property match undefined .How to resolve this issue
{{forumCtrl.question_commentErr}}
asked Sep 3, 2019
{{ forumCtrl.answerArr.length}} Answer
0
{{answer.voteCount}}
Edit
Delete
View More
{{forumCtrl.response_commentErr}}
answered {{answer.date}}
Your Answer
{{forumCtrl.responseErr}}
report this ad
report this ad