收听EACCES:Windows中的权限被拒绝

时间:2019-12-20 16:54:33

标签: node.js windows npm operating-system permission-denied

在我卸载vscode并重新安装后,今天晚上一切都很好,我在尝试运行npm run app时遇到此问题,我不知道如何解决此问题,我试图运行vs代码和命令提示符,或者bash使用管理员身份运行,但没有运气,我看到有很多针对此问题的修复程序,但其中大多数是针对Mac的,他们使用sudo进行了修复,但是我看不到任何针对Windows的好的修复程序,如果有人能帮助我解决此问题

//this issue this my server code 
const express = require("express");
const app = express()
const port = process.env || 8080

app.get("/", (req, res) => {
  res.send("Hello");
});



app.listen(port,()=>{
  console.log("running on 8080")
})

这是完整的错误

events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\BookStore\node_modules\.bin;C:\Users\Samarth's PC\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Samarth's PC\bin;C:\ProgramData\Miniconda3;C:\ProgramData\Miniconda3\Library\mingw-w64\bin;C:\ProgramData\Miniconda3\Library\usr\bin;C:\ProgramData\Miniconda3\Library\bin;C:\ProgramData\Miniconda3\Scripts;C:\Python27;C:\Python27\Scripts;C:\Users\Samarth's PC\AppData\Local\Programs\Python\Python38-32\python.exe;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Microsoft\WindowsApps;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files\heroku\bin;C:\nvm;C:\Program Files\nodejs;C:\Python 3.8;C:\Users\Samarth's PC\AppData\Roaming\npm;C:\Users\Samarth's PC\AppData\Local\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
    at Server.setupListenHandle [as _listen2] (net.js:1283:19)
    at listenInCluster (net.js:1348:12)
    at Server.listen (net.js:1447:5)
    at Function.listen (D:\BookStore\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (D:\BookStore\app.js:11:5)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1327:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EACCES',
  errno: 'EACCES',
  syscall: 'listen',
  address: "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\npm-lifecycle\\node-gyp-bin;D:\\BookStore\\node_modules\\.bin;C:\\Users\\Samarth's PC\\bin;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\local\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Users\\Samarth's PC\\bin;C:\\ProgramData\\Miniconda3;C:\\ProgramData\\Miniconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Miniconda3\\Library\\usr\\bin;C:\\ProgramData\\Miniconda3\\Library\\bin;C:\\ProgramData\\Miniconda3\\Scripts;C:\\Python27;C:\\Python27\\Scripts;C:\\Users\\Samarth's PC\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe;C:\\Program Files\\nodejs;C:\\ProgramData\\chocolatey\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\WINDOWS\\System32\\OpenSSH;C:\\Program Files (x86)\\Yarn\\bin;C:\\Users\\Samarth's PC\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\MongoDB\\Server\\4.0\\bin;C:\\Program Files\\heroku\\bin;C:\\nvm;C:\\Program Files\\nodejs;C:\\Python 3.8;C:\\Users\\Samarth's PC\\AppData\\Roaming\\npm;C:\\Users\\Samarth's PC\\AppData\\Local\\Yarn\\bin;C:\\Users\\Samarth's PC\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Git\\usr\\bin\\vendor_perl;C:\\Program Files\\Git\\usr\\bin\\core_perl",
  port: -1
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bookstore@1.0.0 start: `node app.js "app"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bookstore@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Samarth's PC\AppData\Roaming\npm-cache\_logs\2019-12-20T16_43_00_131Z-debug.log
//Error log is here
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start',
1 verbose cli   'app'
1 verbose cli ]
2 info using npm@6.12.0
3 info using node@v12.13.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle bookstore@1.0.0~prestart: bookstore@1.0.0
6 info lifecycle bookstore@1.0.0~start: bookstore@1.0.0
7 verbose lifecycle bookstore@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle bookstore@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\BookStore\node_modules\.bin;C:\Users\Samarth's PC\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Samarth's PC\bin;C:\ProgramData\Miniconda3;C:\ProgramData\Miniconda3\Library\mingw-w64\bin;C:\ProgramData\Miniconda3\Library\usr\bin;C:\ProgramData\Miniconda3\Library\bin;C:\ProgramData\Miniconda3\Scripts;C:\Python27;C:\Python27\Scripts;C:\Users\Samarth's PC\AppData\Local\Programs\Python\Python38-32\python.exe;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Microsoft\WindowsApps;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files\heroku\bin;C:\nvm;C:\Program Files\nodejs;C:\Python 3.8;C:\Users\Samarth's PC\AppData\Roaming\npm;C:\Users\Samarth's PC\AppData\Local\Yarn\bin;C:\Users\Samarth's PC\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle bookstore@1.0.0~start: CWD: D:\BookStore
10 silly lifecycle bookstore@1.0.0~start: Args: [ '/d /s /c', 'node app.js "app"' ]
11 silly lifecycle bookstore@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle bookstore@1.0.0~start: Failed to exec start script
13 verbose stack Error: bookstore@1.0.0 start: `node app.js "app"`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:210:5)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:210:5)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid bookstore@1.0.0
15 verbose cwd D:\BookStore
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" "app"
18 verbose node v12.13.0
19 verbose npm  v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error bookstore@1.0.0 start: `node app.js "app"`
22 error Exit status 1
23 error Failed at the bookstore@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

7 个答案:

答案 0 :(得分:3)

对我来说,当Windows 10有一些待处理的更新时,这一直在发生。要解决此问题,我需要安装所有待处理的更新,并在此过程中重新启动1-2次。

答案 1 :(得分:3)

嗨,任何来到这里但没有找到任何答案的人。我有一个我认为会有所帮助的答案。它为我解决了这个问题。 在某些情况下,端口上什么都没有运行,但某些应用程序甚至您的代码都无法运行修复程序:

  1. 以管理员身份打开 PowerShell。

  2. 使用以下命令停止 winnat:

    net stop winnat

  3. 使用以下命令再次启动 winnat:

    net start winnat

这在很多情况下为我解决了问题。无需重启。我希望它也能帮到你。

答案 2 :(得分:0)

我通过以下步骤解决了这个问题:

始终使用管理权限

它会起作用

答案 3 :(得分:0)

我已经禁用了防病毒实时保护并已修复。

答案 4 :(得分:0)

我遇到了同样的问题。某些在后台运行的 Windows 应用程序或者您自己启动的进程正在使用您想要监听的端口。 尝试使用随机端口号。例如 5645。如果尝试 2 或 3 次后仍然无法正常工作,则可以确定问题不是由正在使用的端口引起的。

答案 5 :(得分:0)

在这种特殊情况下,它失败了,因为在您的代码端口中不是您认为的那样。请看,process.env 是一个带有环境变量的对象,而不是端口号。

所以代替

const port = process.env || 8080

应该是这样的

const port = process.env.PORT || 8080

我想是因为我在 app.listen(PORT, HOST, callback) 中反转了端口和主机参数,并在搜索为什么它无法以消息 Error: listen EACCES: permission denied localhost 开头时发现了这个问题。

答案 6 :(得分:-1)

尝试此步骤

  • 在运行之前以管理员身份运行命令提示符/ powershell 这个脚本
  • 完全删除node_modules文件夹并重新安装 使用npm install并运行启动脚本