我正在尝试用电子运行express,并遇到“无法分配给只读属性'导出'的对象”错误,这被认为是一个webpack问题。然后我修改了我的代码,因此没有混合导入和要求,但错误仍然存在。它让我感到困惑的是,我的快速包装模块错误只是 ONLY ,而电子模块本身与require
一起工作正常,我现在不知道。这是我的main.js
:
const { app, BrowserWindow } = require('electron')
// after comment the next line, the error would not appear
const { runExpress } = require('../express/app-wrapper')
// ..other codes..
和我的app-wrapper.js
(省略了一些记录器代码):
var app = require('./app')
var http = require('http')
var port = 3000
var server = http.createServer(app)
function runExpress () {
return new Promise(resolve => {
// apply errorHandlers, for the webpack middlewares
// needs to apply before these errorHandlers.
for (let handler of app.errorHandlers) {
app.use(handler)
}
/**
* Get port from environment and store in Express.
*/
app.set('port', port)
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port)
server.on('error', onError)
server.on('listening', () => { resolve() })
})
}
module.exports = {
app,
port,
runExpress
}
(好吧,在电子内部运行表达不是一个好主意,但是我的好奇心在于我,感谢您的帮助)