我的文件夹结构设置如下:
assets/
logo.png
other_web_assets.png
electron/
node_modules
main.js
package-lock.json
package.json
src/
index.js
otherJavascriptFiles.js
index.html
style.css我将ElectronJS从网站中分离出来的原因是,该网站打算通过HTTP提供服务(它不应该没有电子,我只需要用于Firebase身份验证的HTTP协议)。目前,我通过端口5500上的LiveServer VSCode扩展服务于VSCode。
在我的index.html中,我使用require("./src/index.js")加载index.js,在index.js文件中,我使用require与其他javascript文件和其他节点模块通信。
但是,require("./src/index.js")不能从index.html中运行,我总是在开发工具控制台中获得错误Uncaught Error: Cannot find module './src/index'。我尝试过用index.js导入<script src="./src/index.js"></script>,但这会导致相同的错误,使用不同的javascript文件,而我的index.js试图使用require导入该文件。
但是,我可以要求正常的节点模块(例如require("request")),而不会出现任何错误。
有办法解决这个问题吗?
发布于 2020-09-24 15:43:58
若要从js文件导入函数,请使用
import {functionName} from 'path to js file where function is defined'我用的是图片等,而不是js文件。
我建议你用进口。另外,使用导出这个词定义需要导入到其他文件中的函数。
https://stackoverflow.com/questions/64049803
复制相似问题