繁体   English   中英

要求 function 在 nodejs 中 index.js 以外的文件中不可用

[英]Require function unavailable in files other than index.js in nodejs

我在 nodejs 文件夹中有一个主 index.js 文件,其中包含 package.json。 我在同一个文件夹中还有一个 HTML 文件,我需要在那里使用一些库,例如 electron 和 ipcRenderer,但是我不能在文件中使用 require,当我这样做时,js 会为 require() ZC38FC4245AB74D16 引发未捕获的引用错误. 我已将 requirejs 作为依赖项保存在 package.json 文件中。 然而,我仍然面临同样的问题。

有没有办法在不使用 require() 的情况下导入 ipcRenderer 或 electron?

为了解决这个问题,我建议你阅读: https://nodejs.org/en/knowledge/getting-started/what-is-require/

它向您解释了“require”的使用。

更准确地说,您必须至少将您的.html 重命名为.ejs。

要执行,请遵循以下指南: https://ejs.co/

玩得开心:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM