让我们来说明一下:我目前正在为
电子
.
从一开始,我就在处理一个包含类的JS文件。
但我决定创建一个不同的类(以及另一个JS文件),以拥有更好的组织。
所以我做到了。我做了这个文件,最后导出,就像我在很多网站上看到的一样。
不幸的是,当我试图要求我的第一节第二节课时,我得到了这个错误:
未捕获错误:找不到模块“./my module two”
惹人生气的。
我在谷歌上搜索了大约一个小时,为了找到一个解决方案,我尝试了很多没有结果的方法。
我的文件内容就在这里。我认为那是无用的。
my-模块-one.js
// I also tried to require here.
class MyModuleOne
{
constructor() {
this.MyModuleTwo = require('./my-module-two');
}
}
my-模块-2.js
class MyModuleTwo
{
// Literally nothing. But I tried with a constructor for the same issue.
}
module.exports.MyModuleTwo = MyModuleTwo;
索引文件
<!-- Into <head> tags. -->
<script src="js/my-module/my-module-one.js"></script>
我的文件在同一目录中:
myApp/
web/
js/
my-module/
my-module-one.js
my-module-two.js
node_modules/
(other directories)/
main.js
package.json
package-lock.json
当然,所有安装了NPM的库都需要
索引文件
或
my-模块-one.js
像地狱一样工作。
感谢那个将成为我救世主的人!:)