最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用nw.Window.open()打开的nw.js窗口中的“未捕获的ReferenceError:require未定义”

IT培训 admin 5浏览 0评论

使用nw.Window.open()打开的nw.js窗口中的“未捕获的ReferenceError:require未定义”

我觉得我错过了一些简单的事情。

我正在nw.js中开发一个“托盘”应用程序。为此,我将"main"设置为"main.js"中的package.json文件。在main.js中,我实例化了一个Tray对象,并在托盘对象的click事件上调用nw.Window.open('file://' + path.join(__dirname, 'index.html'))

这一切都很好,除了我无法在require内的任何脚本中使用index.html。我收到一个错误说:

Uncaught ReferenceError: require is not defined

请注意,如果我在"main"中将"index.html"设置为package.json,一切正常。当使用index.html打开nw.Window.open('file://' + path.join(__dirname, 'index.html'))时,问题才出现。

我觉得它与node-remote中的package.json选项有关,但我无法弄明白。

回答如下:

更换

nw.Window.open('file://' + path.join(__dirname, 'index.html'))

nw.Window.open('index.html')

做了伎俩。

使用nw.Window.open()打开的nw.js窗口中的“未捕获的ReferenceError:require未定义”

我觉得我错过了一些简单的事情。

我正在nw.js中开发一个“托盘”应用程序。为此,我将"main"设置为"main.js"中的package.json文件。在main.js中,我实例化了一个Tray对象,并在托盘对象的click事件上调用nw.Window.open('file://' + path.join(__dirname, 'index.html'))

这一切都很好,除了我无法在require内的任何脚本中使用index.html。我收到一个错误说:

Uncaught ReferenceError: require is not defined

请注意,如果我在"main"中将"index.html"设置为package.json,一切正常。当使用index.html打开nw.Window.open('file://' + path.join(__dirname, 'index.html'))时,问题才出现。

我觉得它与node-remote中的package.json选项有关,但我无法弄明白。

回答如下:

更换

nw.Window.open('file://' + path.join(__dirname, 'index.html'))

nw.Window.open('index.html')

做了伎俩。

发布评论

评论列表 (0)

  1. 暂无评论