通过 nodejs 安装 Express 时出错

Error installing Express via nodejs

我正在尝试通过 nodeJS 安装 express,我收到的错误告诉我应该重命名我的目录。我的项目文件夹中已经有 运行 npm init,所以我假设设置是正确的。我使用的确切命令是:npm install express --save 和 npm-debug.log 列出了一堆以 "silly" 开头的语句,但最重要的语句(imo)如下:

3242 verbose stack Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3242 verbose stack     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
3242 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
3242 verbose stack     at FSReqWrap.oncomplete (fs.js:123:15)
3242 verbose stack
3242 verbose stack Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3242 verbose stack     at Error (native)
3243 verbose cwd C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron
3244 error Windows_NT 10.0.16299
3245 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "express" "--save"
3246 error node v6.11.2
3247 error npm  v3.10.10
3248 error path C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf
3249 error code EPERM
3250 error errno -4048
3251 error syscall rename
3252 error Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3252 error     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
3252 error     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
3252 error     at FSReqWrap.oncomplete (fs.js:123:15)
3252 error
3252 error Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3252 error     at Error (native)
3252 error  { Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3252 error     at destStatted (C:\Program Files\nodejs\node_modules\npm\lib\install\action\finalize.js:25:7)
3252 error     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:264:29
3252 error     at FSReqWrap.oncomplete (fs.js:123:15)
3252 error
3252 error Error: EPERM: operation not permitted, rename 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\.staging\depd-c51a5acf' -> 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'
3252 error     at Error (native) parent: 'microtrack' }
3253 error Please try running this command again as root/Administrator.
3254 verbose exit [ -4048, true ]`

上下文:我一直在关注 YT 上的 Brad Traversy 的 NodeJS 和 Express 数据库应用程序系列,试图学习一些后端内容以在我的副项目中使用,并且他使用的命令(上面列出的)完美无缺。

提前感谢任何help/suggestions。

检查您的问题是否由名为 .staging 的目录引起。通常当目录以 . means 是一个隐藏的文件夹,所以在这种情况下,安装程序正在避开该文件夹,因此它试图找到不存在的路径 'C:\Users\Leungi5368\Documents\CS Education\Side Projects\TimeManagerElectron\TimeManagerElectron\node_modules\depd'

我正在做一些更多的研究,我发现 运行 npm install 命令 在关闭 atom IDE 之后有效。感谢大家的帮助!

完整线程:https://github.com/npm/npm/issues/12059 答案在页面底部