NodeJS 错误:node.js:810 var cwd = process.cwd();

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19936850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:16:13  来源:igfitidea点击:

NodeJS Error: node.js:810 var cwd = process.cwd();

node.js

提问by user2984480

I'm new to nodeJS and also new to StackOverflow...

我是 nodeJS 的新手,也是 StackOverflow 的新手......

I'm starting to develop my first SPA, using RequireJS to compile my sources into a "dist" folder. I had NodeJS running a basic script to run my server:

我开始开发我的第一个 SPA,使用 RequireJS 将我的源代码编译到“dist”文件夹中。我让 NodeJS 运行一个基本脚本来运行我的服务器:

var connect = require('connect');
connect.createServer(
    connect.static(__dirname)
).listen(8080);

Everything was working well, till I compile my src again. That replaced all the files served by my server, so I though I would restart Node. I Ctrl^C and from this moment, I can't get Node to start again. When I try to run:

一切正常,直到我再次编译我的 src。这取代了我的服务器提供的所有文件,所以我虽然会重新启动 Node.js 文件。我 Ctrl^C 从这一刻起,我无法让 Node 重新启动。当我尝试运行时:

olivier$ node server.js 

I get this error:

我收到此错误:

node.js:810
    var cwd = process.cwd();
                  ^
Error: ENOENT, no such file or directory
    at Function.startup.resolveArgv0 (node.js:810:23)
    at startup (node.js:58:13)
    at node.js:901:3

What's strange is that I get the same error just trying to start NodeJS, simply doing:

奇怪的是,我在尝试启动 NodeJS 时遇到了同样的错误,只需执行以下操作:

olivier$node

Anyone has an idea of what I can do beside uninstalling Node and reinstalling it ?

任何人都知道除了卸载 Node 并重新安装它之外我还能做什么?

回答by fiatjaf

I got this when trying to run the Node REPL from a directory I had already deleted (from another shell). Don't let this happen to you or you will be ashamed.

我在尝试从我已经删除的目录(从另一个 shell)运行 Node REPL 时得到了这个。不要让这发生在你身上,否则你会感到羞耻。

回答by robertklep

Could it be that RequireJS is also recreating the directory that contains your server.js?

是不是 RequireJS 也在重新创建包含您的server.js?

Try and see if this works:

尝试看看这是否有效:

$ cd $PWD; node server.js

Although it seems useless to change the directory to the current directory, the rationale is that when a directory gets deleted while it's the current working directory of your shell, the shell is left in a dangling state because it's still 'attached' to the previously deleted directory. This also affects any processes that you start from that shell (like Node), and can yield confusing errors.

尽管将目录更改为当前目录似乎没有用,但其基本原理是,当目录在 shell 的当前工作目录下被删除时,shell 仍处于悬空状态,因为它仍然“附加”到先前删除的目录目录。这也会影响您从该 shell(如 Node)启动的任何进程,并可能产生令人困惑的错误。

By executing cd $PWD, you make sure your shell gets 'reattached' to the newly created version of the directory, solving the dangling state.

通过执行cd $PWD,您可以确保您的外壳程序“重新附加”到新创建的目录版本,从而解决悬空状态。

回答by Parth Patel

I faced the same issue.

我遇到了同样的问题。

To Solve this issue enter below command :

要解决此问题,请输入以下命令:

cd ..

OR

或者

Check your directory in Terminal/CMD. and Change it.

Actually this issue coming when you deleted your project folder form your PC and without change directory try to run any command of React-Native.

实际上,当您从 PC 中删除项目文件夹并且不更改目录尝试运行 React-Native 的任何命令时,就会出现这个问题。

回答by selvamraj.sck

Remove the folder in another terminal and save its the file, Open the new terminal on folder structure, and run the file.

删除另一个终端中的文件夹并保存其文件,在文件夹结构上打开新终端,然后运行该文件。

Folder structure was not available on the current terminal session. When you close it and re-open the terminal in your file directory, the structure will be refreshed.

文件夹结构在当前终端会话中不可用。当您关闭它并在您的文件目录中重新打开终端时,结构将被刷新。

回答by user9147812

use

cd .

is ok.

没问题。

But the problem is in server

但问题出在服务器上

回答by Prabhu S

I faced the same kind of a problem when starting the app in cluster mode via pm2.

通过 pm2 以集群模式启动应用程序时,我遇到了同样的问题。

I did the following & it worked, * executed pm2 kill * Removed node_modules * npm install * start the application Reference: https://github.com/Unitech/pm2/issues/1244

我做了以下工作,* 执行 pm2 kill * 删除 node_modules * npm install * 启动应用程序参考:https: //github.com/Unitech/pm2/issues/1244

Then it started to work as expected. Hope it helps.

然后它开始按预期工作。希望能帮助到你。

回答by Ravinder Reddy Kottabad

If we try to do any actions on an already deleted file from another shell then we'll face this issue. Just restart the system it'll work normally ( It worked for me )

如果我们尝试从另一个 shell 对已删除的文件执行任何操作,那么我们将面临这个问题。只需重新启动系统它就会正常工作(它对我有用)