Electron-packager:找不到模块

nav*_*978 16 electron

我尝试使用electron-Packager和此命令打包我的应用程序:

electron-packager . FooBar --platform=darwin --arch=x64 --version=0.36.9
Run Code Online (Sandbox Code Playgroud)

(我正在使用MacOsx)应用程序已创建,但是当我运行它时,我会看到一个弹出窗口显示:

未捕获的异常:

Error: Cannot find module '/Users/myUser/myApp/FooBar-darwin-x64/FooBar.app/Contents/Resources/app/app:/host/menu.html'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Object.<anonymous> (/Users/myUser/myApp/FooBar-darwin-x64/FooBar.app/Contents/Resources/atom.asar/browser/lib/init.js:158:8)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:151:18)
    at node.js:1007:3
Run Code Online (Sandbox Code Playgroud)

在这个文件夹中:"/ Users/myUser/myApp /FooBar-Darwin-x64/FooBar.app/Constate/Resources/app"有条目指向html文件"menu.html",但似乎电子找不到它.. .

这是我的app.js:

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

var mainWindow = null;


// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {

  // Create the browser window.
  mainWindow = new BrowserWindow({width: 1024, height: 768});

  // and load the index.html of the app.
  mainWindow.loadUrl('file://' + __dirname + '/menu.html');

  mainWindow.openDevTools({detach: true});

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    mainWindow = null;
  });

});
Run Code Online (Sandbox Code Playgroud)

您对可能出现的问题有什么想法吗?

谢谢.

phu*_*gle 15

你可以尝试两件事:

  • 对我来说,我必须在 `package.json` 中指定 `"main": "./dist/main.js"`,因为它试图找到可能是默认值的 `index.js`。我用“electron-quick-start-typscript”在打字稿中开始了这个项目。 (5认同)
  • 我已将我的 `devDependencies` 切换为 `dependencies`,它似乎正在工作! (2认同)

Lac*_*mov 5

对我来说,问题是模块依赖项列在 package.json 的“devDependencies”中

将它们移至“依赖项”并再次运行 npm install 解决了问题。