Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

node.js - NPM Error : Error: EROFS: read-only file system, mkdir '/npm'

I created an index.js, index.html and package.json file and I wanted to add express. When I write 'npm install express' in the terminal, I'm getting the error below. So far, I tried 'sudo npm install -g express', deleting node and npm completely and re-install. I also went through other questions over here but none of them worked out for me. Whatever I write with npm I get the same error. (I'm using macOS)

Do you have any suggestions?

This is the error I am getting:

Error: EROFS: read-only file system, mkdir '/npm'

TypeError: Cannot read property 'loaded' of undefined

    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)

    at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)

    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20

    at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)

    at /usr/local/lib/node_modules/npm/lib/npm.js:263:24

    at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7

    at Array.forEach (<anonymous>)

    at /usr/local/lib/node_modules/npm/lib/config/core.js:80:13

    at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)

    at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:171:20)

/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97

  var doExit = npm.config.loaded ? npm.config.get('_exit') : true

                          ^

TypeError: Cannot read property 'loaded' of undefined

    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)

    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)

    at process.emit (events.js:223:5)

    at process._fatalException (internal/process/execution.js:150:25)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error means that you have no permission to install anything with npm at the path /npm.
To verify this run npm root -g. This should return /npm.

Note that /npm ist not the default installation path on MacOS (see https://stackoverflow.com/a/35638528/1754076).

Checkout your npm configuration file and change the default installation path to something where you do have write access. You can also use npm itself to change the default installation path.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...