gpt4 book ai didi

javascript - 使用 nw.Window.open() 打开的 nw.js 窗口中的 "Uncaught ReferenceError: require is not defined"

转载 作者:行者123 更新时间:2023-12-03 02:51:11 25 4
gpt4 key购买 nike

我觉得我错过了一些简单的东西。

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

一切工作正常,除了我无法在 index.html 内的任何脚本中使用 require 。我收到一条错误消息:

Uncaught ReferenceError :未定义要求

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

我感觉它与package.json中的node-remote选项有关,但我不太明白。

最佳答案

更换

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

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

成功了。

关于javascript - 使用 nw.Window.open() 打开的 nw.js 窗口中的 "Uncaught ReferenceError: require is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47851122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com