现在我正在尝试学习如何使用电子对桌面应用程序进行编程,但是在尝试使用在windows 10 x64上使用nodejs x32进行电子预建的'npm start'时出现此错误:
App threw an error during load
Error: Cannot find module 'browser-window'
at Module._resolveFilename (module.js:438:15)
at Function.Module._resolveFilename (C:\Users\Alejandro\Documents\Proyectos\player\node_modules\electron-prebuilt\dist\resources\electron.asar\common\reset-search-paths.js:35:12)
at Function.Module._load (module.js:386:25)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Alejandro\Documents\Proyectos\player\index.js:4:25)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
这是我的代码:
的package.json
{
"name": "player",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"electron-prebuilt": "^1.2.7"
}
}
index.js
const electron = require('electron')
const {app} = electron
const {BrowserWindow} = require('browser-window')
app.on('ready',function(){
var mainWindow = new BrowserWindow({
width:800,
height:600
})
})
节点版本:4.4.5
npm版本:2.15.5
答案 0 :(得分:11)
@ morecchia808是正确的,访问内置模块的方式在Electron v1.0中已经改变。您的代码可以修改如下:
const electron = require('electron')
const {app, BrowserWindow} = electron