NodeJS ReferenceError:“require is not defined”即使我使用的是 CommonJS

问题描述

出于某种原因,我无法在 Electron 中使用 NodeJS 来要求 fileSystem。这是错误

Uncaught ReferenceError: require is not defined

package.json:

{
  "type": "commonjs","name": "incontroversion","version": "1.0.0","description": "First-order logic solution","main": "Scripts/main.js","scripts": {
    "test": "test.js","start": "electron ."
  },"repository": {
    "type": "git","url": "https://github.com/gabetucker2/incontroversion"
  },"keywords": [
    "incontroversion"
  ],"author": "Gabe Tucker","license": "MIT","devDependencies": {
    "electron": "^13.1.6"
  }
}

preload.js:

const fileSystem = require('fs')//the line of the error

当我将这一行放在 main.js 中时,错误消失了,然后我在使用 fileSystem 而不是说 fileSystem 未定义的那一行出现错误

我已经坚持了很长一段时间,任何可以帮助我解决这个问题的东西都将不胜感激。我附上了一张我所看到的图片,以防万一。

enter image description here

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...