hot-import icon indicating copy to clipboard operation
hot-import copied to clipboard

新手求答:如何监听export default而非module.exports

Open xmsz opened this issue 6 years ago • 4 comments

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去用

xmsz avatar Nov 24 '18 07:11 xmsz

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

xmsz avatar Nov 24 '18 15:11 xmsz

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.

huan avatar Nov 27 '18 17:11 huan

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就能看到报错了 image


第二个运行的时候,直接就能看到报错了 image

第三个运行的时候,就不会有问题

xmsz avatar Nov 28 '18 07:11 xmsz

Thanks for the test repo, I'll look into it later.

huan avatar Nov 28 '18 08:11 huan