hot-import
hot-import copied to clipboard
新手求答:如何监听export default而非module.exports
a.js
router = await hotImport("./b.js");
b.js
const test = new otherClass()
export default test;
运行时会出现,无法获取test的情况
如果改为 a.js
router = await hotImport("./b.js");
router()
b.js
export default () = new otherClass()
那么运行没问题,但改了b的内容以后,a内容并不更新
只有改为module.exports =new otherClass(),才能更新
项目是通过babel-node 运行,因为想要用es6的写法,不太希望混着module.exports去用
11.25更新 会触发这个还有一个条件是,b.js被a.js动态引用。
也就是a.js
await hotImport("./b.js", false);
c.js 更改代码
b.js 也更改代码
这时候就b.js引用c.js就会报错
再记录一个问题
如果监听c.js 运行出现了错误,如果这时候修改了b.js(引用c.js的文件) ,就不能正确引用了,会提示TypeError: xxxx is not a constructor
同时,如果console.log(hotImport("./c.js"))
,显示的就会是undefined
;
本来以为可以通过disable来达到重启效果,但发现也不行
if (!_c) {
await hotImport("./c.js", false);
await hotImport("./c.js", true);
}
所以有没有办法,强制重新Import c.js
Can you post a minimum run-able code with steps in details to let me reproduce your problem?
I'll be able to look into it for you if I can reproduce it.
And please make sure you have read all the examples and the unit tests so that you can understand how to use hot-import right.
Thank you very much.
I have invite you to the test project.
三个脚本
"load_failed": "babel-node --nolazy ./load_failed/a.js",
"export_test": "babel-node --nolazy ./export_test/a.js",
"export_test:work": "babel-node --nolazy ./export_test/c.js"
第一个运行的时候,修改b.js
里的_num
就能看到报错了
第二个运行的时候,直接就能看到报错了
第三个运行的时候,就不会有问题
Thanks for the test repo, I'll look into it later.