下午好,我无法导入电子模块。我有以下错误:无法找到模块'电子'。 我的结构:
main.js电子:
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadURL(`file://${__dirname}/index.html`)
mainWindow.webContents.openDevTools()
mainWindow.setMenu(null);
mainWindow.on('closed', function () {
mainWindow = null;
})
}
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
});
const ipc = require('electron').ipcMain
ipc.on('get-app-path', function (event) {
event.sender.send('got-app-path', app.getAppPath())
})
我的index.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>X</title>
<script>
window.$ = window.jQuery = require('jquery');
var electron = require('electron');
document.write('<base href="' + document.location + '" />');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body style="padding-top: 70px;">
<app-root>
loading...
</app-root>
</body>
</html>
我在组件中的导入:
import { ipcRenderer } from 'electron';
我测试过: typings.d.ts:
declare var System: any;
declare var electron: any;
在脚本index.html中声明:
var electron = require('electron');
和组件:
electron.ipcRenderer.on('got-app-path', function (event, path) {
...
});
没有任何反应......
有什么建议吗?感谢!
答案 0 :(得分:0)
我的问题通过声明来解决:
Observable.timer(500).subscribe(() => this.success = true)
index.html和typings.d.ts中的:
<script>
var electron = require('electron');
</script>
我的组件:
declare var electron: any;
部分问题是异步!