0

I have installed node v10 and trying to install Ionic in my mac.

When I run sudo npm install -g ionic, it shows ionic 4 installed successfully.

But when run ionic -v or ionic serve, it shows the following error

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module './fs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/ionic/node_modules/fs-extra/lib/index.js:6:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

I have searched for the solution but I could not find any working solution for me.

Any help is appreciated.

Sujan Gainju
  • 4,273
  • 2
  • 14
  • 34
  • 1
    P.S. It is strongly advised to **not** run `npm install -g` with `sudo`. See https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally if you're having trouble globally installing packages without `sudo`. – Edric Jan 17 '19 at 14:38
  • @Edric You are right. It solved the issue. – Sujan Gainju Jan 17 '19 at 14:53

2 Answers2

1

@Edric Comment helped me out.

It is strongly advised to not run npm install -g with sudo.

I uninstalled the ionic and reinstalled without sudo and now it is working just great.

Thank you @Edric.

Sujan Gainju
  • 4,273
  • 2
  • 14
  • 34
0

The reason you are facing this issues is because you have installed Ionic with root permission. So ionic -v is not able to access installed files.

Try with sudo i.e. sudo ionic -v

Nitishkumar Singh
  • 1,781
  • 1
  • 15
  • 33