【发布时间】:2021-08-25 22:59:21
【问题描述】:
我正在发现 Electron,但我遇到了一个问题:我无法在我的 "test.js" 脚本中实现我的 "common.js" 文件.
这是我项目的架构:
rootProject
-features(folder)
-common.js
-test.js
-index.html
common.js
const hello = "hello";
module.exports = { hello };
test.js
const {hello} = require("./common.js");
console.log(hello);
index.html
<body>
<h1>Hello World!</h1>
<div class="flex-container">
<span id="timeAfterRefreshGasFees"></span>
<span id="rapid"></span>
<span id="fast"></span>
<span id="standard"></span>
<span id="slow"></span>
</div>
<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
<!-- <script src="./features/common.js"></script> -->
<script src="./features/test.js"></script>
</body>
在这种情况下,我得到:错误:找不到模块'./common.js'
如果我在 index.html 中取消注释
我想要一个 common.js 文件,我可以在其中放入一些东西(比如 const 等...)
我该如何解决?
我已经尝试了所有这些解决方案:Getting Unexpected Token Export
谢谢!
第一次解决后编辑:
我添加了这些行来获取 nodeIntegration
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
并删除了 common.js
中的 中 require 时出现此错误: 找不到模块“./common.js”【问题讨论】:
标签: javascript node.js module electron