【问题标题】:ReferenceError: Can't find variable: require node.jsReferenceError:找不到变量:需要 node.js
【发布时间】: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)

http://i65.tinypic.com/mwp3md.png

【问题讨论】:

  • 你在前端 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


【解决方案1】:

找到解决方案.. 忽略了我在 list.html / 客户端代码中包含 requesthandle.js 的事实。感谢您对 Arpit Solanki 的帮助!似乎您的第一句话包括解决方案:我错误地使用它前端..

【讨论】:

    猜你喜欢
    • 2017-02-26
    • 1970-01-01
    • 2017-11-24
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2014-02-20
    相关资源
    最近更新 更多