10

Catch this error after npm i. Version npm - 8.0.0, nodejs - 16.11.0.

npm ERR! Cannot read properties of undefined (reading 'isServer')
Ivan Kharkivskyi
  • 569
  • 1
  • 4
  • 22
  • Were you able to solve the problem? – Ali Ihsan Elmas Jun 26 '22 at 16:04
  • I guess we need more information. Which packages do you install? Can you provide more error logs? Can you provide the package.json? The error says, that some object is undefined when calling and some function tries to access the "isServer" property of it, which in turn doesn't work... – Der Alex Jun 27 '22 at 06:04

16 Answers16

8

I had the same issue with close versions of node and npm. I was using a shared connection from my phone since I wasn't home. When I get back home and used my WiFi things got back to normal.

If you are using such kind of connection then it is probably that causes this issue.

Klaymant
  • 158
  • 5
  • 4
    I highly recommend trying this solution. It worked for me. I was using mobile phone, but switched to pocket wifi(still mobile but not through tethering) and it worked. Prior to this, I tried everything: npm cache verify/clean/--force, delete cache folder manually, installed lower versions on node&npm, cleared temp folder and restarting my machine. And it worked for creating new projects and npm install on existing projects. – Miguel Ormita Nov 25 '21 at 19:50
  • This seems to be a network problem, I had the same problem but had to use 4G instead of the WiFi – TheDeveloo Jun 20 '22 at 05:41
  • It worked for me. Initially, I created a new react project while on my company's VPN. Got the same error mentioned by OP. Tried cache clean, audit fix etc. Nothing worked. Then stumbled upon this thread. I switched back to my personal wifi and the problem was solved. – SangyK Jun 24 '22 at 09:28
3

Try to use npm with specific version

for example i was trying to use npm install -g truffle and it did not work

but this one work npm install -g truffle@5.0.5

Tanjin Alam
  • 1,728
  • 13
  • 15
3

I updated npm and that fixed it! You can update npm like so:

npm install -g npm@latest

If running this command doesn't work then you can try installing npm packages in an Admin Environment.

Hope this helps!

Dovi Rosner
  • 115
  • 1
  • 8
3

The issue could be due to the network, try to change the network and retry. This solved my issue :)

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 08 '22 at 13:14
  • Welcome to SO! Although your insight may solve the OP problem, there is an already accepted answer that say it while providing more details than yours. – Marcelo Scofano Diniz Nov 09 '22 at 15:32
1

I've got the same issue, then I updated npm to 8.3.0, and the problem is solved.

pokz
  • 11
  • 1
1

Copying the npmrc.5 file from: C:\Program Files\nodejs\node_modules\npm\man\man5 to C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm seemed to work for me:

Copy-Item -Path C:\Program Files\nodejs\node_modules\npm\man\man5 -Destination C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm –Passthru

FanoFN
  • 6,815
  • 2
  • 13
  • 33
1

Try stable Nodejs version 14.16.1 instead of 16. Nodejs 14.16.1 Link

nipun-kavishka
  • 842
  • 12
  • 21
1

Update the latest version of Node.js. Then try to install npm the issue won't come. Check out this URL https://nodejs.org/en/ and install a version recommended for most users.

1

I had this same issue, turning off all port forwarding on my router helped.

xxfogs
  • 59
  • 1
  • 6
1

Whenever, I saw this problem. I restarted the computer and it working immediately. I recommend trying this solution.

0

Based on what I've read on issues related, it seems like there's conflicting global packages and node versions.

Please try uninstalling both node and npm and try again.

Check out these issues for more details:

Node error Cannot read property 'resolve' of undefined

Cannot read property 'resolve' of undefined when using npm to install a package

0

I had the same issue and tried all the possible solutions. None of them worked. And finally, when I restarted my PC, it worked like a charm :).

Shamim
  • 216
  • 1
  • 7
  • *Something worked.* But it was only active/visible after the reboot. Just rebooting does not fix such errors. – Eric Aya Jan 19 '22 at 10:21
0

It happened to me because of the node.js version and an npm update.

  1. Uninstall nodejs
  2. Delete folder C:\Users\Administrator\AppData\Roaming\npm
  3. Install nodejs (v17.x)
  4. In your project folder:
npm install -g npm@8.3.2
npm i --package-lock-only
npm audit fix --force

It worked for me. I hope it helps you :)

0

When I had this problem, I was trying to deploy my NodeJs server in Heroku. The problem was I forgot to load the enviroment variables manually, so it was related to the connection to the DB, that was failing. It happened also locally for the same reason and it was still related to the failing connection to the DB.

-1

I kept running into this problem in different scenarios. I found that because I had used a VPN during my computer session, but not during the time I ran 'npm install', it was throwing this error. I simply reinstalled and restarted and did not enable my VPN during that session. Although, you may not have to completely reinstall-- only restart you PC without using a VPN after restart-- I do not know as I have not tried.

(Specifically I was using Express VPN)

Update: I ran into the problem again immediately after a fresh install and restart. Again I restarted my computer (without a fresh install as I had just reinstalled it.) This seemed to work for the moment. Will update with any permanent fixes I come across.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '22 at 10:15
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30984562) – Sebastiano Schwarz Feb 10 '22 at 19:48
-2

Change your network and try again ,this worked for me!

  • 3
    This is the same solution as in [this other answer](https://stackoverflow.com/a/74318186/2227743). – Eric Aya Mar 07 '23 at 12:43