简体   繁体   中英

Ionic/Angular Issue Cannot find module './fs'

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.

@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.

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 ie sudo ionic -v

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM