无法使用npm start:“电子”来启动电子快速启动应用。

时间:2020-09-26 15:22:05

标签: javascript node.js npm electron

我是电子新手,我尝试按照确切的程序从文档创建电子快速入门应用。但是npm start无法启动应用程序,并引发模块未找到错误。我的目录结构,package.json文件,index.js文件和错误日志如下所示。我已经看过一个解决方案,说要删除node_modules文件夹并再次运行npm install,但它对我不起作用。任何帮助将不胜感激。

目录结构

-electronfirst

--node_modules
--index.html
--index.js
--package.json
--package-lock.json

package.json

{
  "name": "electronfirst",
  "version": "1.0.0",
  "description": "my first electron app",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "Jose Dominic",
  "license": "ISC",
  "devDependencies": {
    "electron": "^10.1.2"
  }
}

index.js

const { app, BrowserWindow } = require('electron')

function createWindow () {
  // Create the browser window.
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  // and load the index.html of the app.
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

错误

PS G:\PROJECTS\Btech Project\Reference & experiments\Electronfirst> npm start

> electronfirst@1.0.0 start G:\PROJECTS\Btech Project\Reference & experiments\Electronfirst
> electron .

'experiments\Electronfirst\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:628
    throw err;
    ^

Error: Cannot find module 'G:\PROJECTS\Btech Project\electron\cli.js'
?[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)?[39m
?[90m    at Function.Module._load (internal/modules/cjs/loader.js:527:27)?[39m
?[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:840:10)?[39m
?[90m    at internal/main/run_main_module.js:17:11?[39m {
  code: ?[32m'MODULE_NOT_FOUND'?[39m,
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electronfirst@1.0.0 start: `electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electronfirst@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Josu\AppData\Roaming\npm-cache\_logs\2020-09-26T15_07_44_322Z-debug.log

0 个答案:

没有答案