【发布时间】:2017-12-11 11:42:13
【问题描述】:
我已经尝试了这个问题的相关解决方案(例如,通过'package.json'添加依赖项并运行npm install)但不幸的是他们没有解决它。问题是当我从以下讨论中接受的答案运行代码时: Node.js, Ajax sending and receiving Json
一切正常。 Ajax 调用有效,我得到了数据的结果。但是在控制台中我得到了错误。
'ReferenceError: Can't find variable: require' (Globale code — requesthandle.js:2ReferenceError: Can't find variable: require)
有什么想法可能是这里的问题吗?谢谢!
这是我正在使用的代码:
requesthandle.js(服务器端,通过执行节点 requesthandle.js)==>
http://i67.tinypic.com/24zbyma.png
和
list.html(通过访问 mydomain/list.html)
【问题讨论】:
-
你在前端 JavaScript 上使用 require 吗?
-
感谢您的快速回复;我在后端 javascript 上使用 require。
-
不确定,但看起来您的节点安装已损坏。尝试在 node.js 控制台上使用 require
-
这给出以下输出:{ [Function: require] resolve: [Function], main: undefined, extensions: { '.js': [Function], '.json': [Function] , '.node': [Function] }, cache: {} } > require("http") { IncomingMessage: { [Function: IncomingMessage] super_: { [Function: Readable] ReadableState: [Function: ReadableState], super_: [对象],_fromList:[函数:fromList]}},方法:['CHECKOUT','CONNECT','COPY','DELETE','GET','HEAD','LOCK',....是这可以吗?
-
那么要求工作正常。将您的代码发布到您收到错误的地方。还要发布你是如何运行它的。没有代码似乎很难找到问题
标签: node.js dependencies