Node.js npm安装仅在与sudo一起使用时工作

Node.js npm安装仅在与sudo一起使用时工作,node.js,npm,npm-install,Node.js,Npm,Npm Install,当我在没有sudo的情况下启动npm I时,会出现这个错误。和sudo一起工作很好。我修复了所有权限,安装了没有sudo的节点,但是错误仍然发生 npm ERR! code E400 npm ERR! 400 Bad Request: typescript@https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz npm ERR! A complete log of this run can be found in: npm ER

当我在没有sudo的情况下启动npm I时,会出现这个错误。和sudo一起工作很好。我修复了所有权限,安装了没有sudo的节点,但是错误仍然发生

npm ERR! code E400
npm ERR! 400 Bad Request: typescript@https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/david/.npm/_logs/2018-06-01T08_01_21_010Z-debug.log
编辑1: 以下是日志文件的最后几行:

node -v
v8.11.2

npm -v
5.6.0
Edit2:我重新安装了node并遵循了指南,现在我得到了一个不同的错误:

9991 verbose stack Error: 400 Bad Request: typescript@https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz
9991 verbose stack     at fetch.then.res (/usr/lib64/node_modules/npm8/node_modules/pacote/lib/fetchers/registry/fetch.js:42:19)
9991 verbose stack     at tryCatcher (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/util.js:16:23)
9991 verbose stack     at Promise._settlePromiseFromHandler (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/promise.js:512:31)
9991 verbose stack     at Promise._settlePromise (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/promise.js:569:18)
9991 verbose stack     at Promise._settlePromise0 (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/promise.js:614:10)
9991 verbose stack     at Promise._settlePromises (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/promise.js:693:18)
9991 verbose stack     at Async._drainQueue (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/async.js:133:16)
9991 verbose stack     at Async._drainQueues (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/async.js:143:10)
9991 verbose stack     at Immediate.Async.drainQueues (/usr/lib64/node_modules/npm8/node_modules/bluebird/js/release/async.js:17:14)
9991 verbose stack     at runCallback (timers.js:810:20)
9991 verbose stack     at tryOnImmediate (timers.js:768:5)
9991 verbose stack     at processImmediate [as _immediateCallback] (timers.js:745:5)
9992 verbose cwd /home/david/Dev/Projects/MobileInfoApp/LHMobileApp
9993 verbose Linux 4.16.12-1-default
9994 verbose argv "/usr/bin/node8" "/usr/bin/npm-default" "i"
9995 verbose node v8.11.2
9996 verbose npm  v5.6.0
9997 error code E400
9998 error 400 Bad Request: typescript@https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz
9999 verbose exit [ 1, true ]
未处理的拒绝错误:请求的配置键无效:singleuffer@5.1.2摘录至/home/david/Dev/Projects/MobileInfoApp/LHMobileApp/n
在pudGet(/usr/local/lib/node_modules/npm/node_modules/figgy pudding/index.js:31:11)
在FiggyPudding.get(/usr/local/lib/node_modules/npm/node_modules/figgy pudding/index.js:13:12)
在Object.get(/usr/local/lib/node_modules/npm/node_modules/figgy pudding/index.js:71:16)
at_parse(/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:138:12)
在解析时(/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:125:12)
在Object.checkData(/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:216:9)
写入时(/usr/local/lib/node_modules/npm/node_modules/cacache/lib/content/write.js:34:31)
在putData(/usr/local/lib/node_modules/npm/node_modules/cacache/put.js:25:10)
在Object.x.put(/usr/local/lib/node_modules/npm/node_modules/cacache/locales/en.js:28:37)
在readFileAsync.then.data(/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/file.js:38:28)
在tryCatcher(/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
在Promise.\u结算PromiseFromHandler(/usr/local/lib/node\u modules/npm/node\u modules/bluebird/js/release/Promise.js:512:31)
在Promise._结算Promise(/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/Promise.js:569:18)
在Promise._settlePromise0(/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/Promise.js:614:10)
在Promise._结算Promises(/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/Promise.js:693:18)
按承诺履行(/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/Promise.js:638:18)
npm错误!我从没打过电话!
npm错误!这是npm本身的一个错误。请通过以下地址报告此错误:
npm错误!
npm错误!此运行的完整日志可在以下位置找到:
npm错误/home/david/.npm/_logs/2018-06-04T07_53_53_015 z-debug.log

这肯定是文件夹权限问题。解决这个问题有多种方法,本文将对此进行详细解释


对于Debian发行版,下面应该允许您在不使用sudo的情况下运行
npm安装

将您的npm前缀更改为您的用户具有写入权限的位置

npm配置集前缀=$HOME/david/

然后运行以下命令并将其添加到
.bashrc

export PATH=$HOME/david/bin:$PATH

取得/usr/local的所有权

sudo chown-R$USER/usr/local


信用卡进入

您正在执行哪个命令?原因根据您的系统设置,安装全局程序包可能需要一些特权…您能让我们查看调试文件
/home/david/.npm/\u logs/2018-06-01T08\u 01\u 21\u 010Z-debug.log
中的日志吗?可能是最后几行或您认为有趣的信息。我正在执行npm I,在我们的项目文件夹中,包含一个package.json.1。我试过用sudo,效果很好,但是我不想一直用sudo。它应该在没有sudo的情况下工作。2.第二个解决方案是更改npm前缀,我已经这样做了,但结果仍然是一样的。3.我不想拥有我的/usr/本地目录的所有权。4.我没有使用全局软件包,我需要的所有东西都在projectfolder中。那么你应该使用npm install package_name而不是npm install-g package_name。这将在您的开发文件夹中安装节点模块。我没有使用“-g”。不确定是什么导致了错误。但是,也许您可以尝试执行以下命令:
npm clean cache
npm install package\u name
Unhandled rejection Error: invalid config key requested: singleuffer@5.1.2 extracted to /home/david/Dev/Projects/MobileInfoApp/LHMobileApp/n
    at pudGet (/usr/local/lib/node_modules/npm/node_modules/figgy-pudding/index.js:31:11)
    at FiggyPudding.get (/usr/local/lib/node_modules/npm/node_modules/figgy-pudding/index.js:13:12)
    at Object.get (/usr/local/lib/node_modules/npm/node_modules/figgy-pudding/index.js:71:16)
    at _parse (/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:138:12)
    at parse (/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:125:12)
    at Object.checkData (/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:216:9)
    at write (/usr/local/lib/node_modules/npm/node_modules/cacache/lib/content/write.js:34:31)
    at putData (/usr/local/lib/node_modules/npm/node_modules/cacache/put.js:25:10)
    at Object.x.put (/usr/local/lib/node_modules/npm/node_modules/cacache/locales/en.js:28:37)
    at readFileAsync.then.data (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/file.js:38:28)
    at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:638:18)

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/david/.npm/_logs/2018-06-04T07_53_53_015Z-debug.log