简体   繁体   中英

electron-reload typescript compiled to a wrong object ( to be electronReload['default'])

I am trying to learn typescript with electron a bit, using a template "electron-quick-start-typescript" ( https://github.com/electron/electron-quick-start-typescript ). I want to add a hot reload function to the template so I could hot reload while editing the code. I am trying to add

import electronReload from "electron-reload";
electronReload(__dirname, {});

these two lines of code, but after the compilation it became

var electron_reload_1 = require("electron-reload");
(0, electron_reload_1["default"])(__dirname, {});

where electron_reload_1["default"] cannot be recognised. I can run the compiled js while I manually changed electron_reload_1["default"] to electron_reload_1 .

I guess the problem is because in electron-reload lib, it is not using export default module to export a function. Does anyone has experience on making typescript + electron hot reloadable? Thank you.

I just found that adding "esModuleInterop": true in tsconfig.json would solve this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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