未捕获的ReferenceError:未定义进程 [英] Uncaught ReferenceError: process is not defined

查看:193
本文介绍了未捕获的ReferenceError:未定义进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node.js来创建一个Web应用程序。当我运行应用程序时(通过在浏览器上打开index.html或在终端上使用命令npm start)我得到两个错误:

I am using node.js to create a web application. When I run the application (either by opening index.html on the browser or using the command "npm start" on the terminal) I get two errors:

未捕获的ReferenceError:过程未定义

Uncaught ReferenceError: process is not defined

未捕获ReferenceError:未定义require

Uncaught ReferenceError: require is not defined

我解决了require is not defined错误,具体包括在我的index.html头标记中指向的链接脚本,其中定义了require函数。
但是,我找不到类似过程函数的东西。

I solved the "require is not defined" error by specifically including in my index.html head tag the link to this script, where the require function is defined. However, I cannot find something similar for the process function.

我的问题是双倍的:


  1. 为什么需要重新定义内置的node.js模块?为什么他们不被认可,那就是内置模块?术语内置模块是否意味着模块不需要外部/第二次重新定义?

  1. Why do built-in node.js modules need to be re-defined? Why are they not recognized as they are, that is "built-in modules"? Doesn't the term "built-in module" mean that a module need not be redefined externaly/second-handedly?

有没有办法解决这个问题问题?我的脚本非常简单,我只是想尝试使用node.js的基本功能,所以我无法弄清楚我可能做了什么错误。

Is there a way to solve this problem? My script is very simple, I am just trying to use a basic function of node.js, so I cannot figure out what errors I might have done.

如果有人遇到这个问题并且找到了解决问题的方法或者发生这种情况的原因,那么你将会有很大的帮助。

If anyone has come about this problem and has found a way around it or a reason this happens, you would be of great help.

推荐答案

Node.js代码必须由节点进程运行,而不是浏览器(代码必须在服务器中运行)。

Node.js code must be run by the node process, not the browser (the code must run in the server).

要运行代码,必须运行以下命令:

To run the code, you must run the command:

node server.js

然后您可以通过输入 http:// localhost:8080 ,例如。您必须具有所需服务器代码的文件server.js(或其他)(在本例中,在端口8080中创建Web服务器)。

And then you can access your server from a browser by typing "http://localhost:8080", for example. You must have a file server.js (or whatever) with the server code you want (in this case, creating a web server in port 8080).

您可以关注这个简单的例子,使用express作为http服务器模块: http://expressjs.com/starter/hello- world.html

You can follow this easy example, using express as http server module: http://expressjs.com/starter/hello-world.html

这篇关于未捕获的ReferenceError:未定义进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆