node modules not found after packaging electron app with electron-forge for window

Viewed 1508

Electron app was initialized using electron-forge webpack template and everything works perfectly for macOs. While running the dev version using electron-forge start the app loads perfectly on windows. Once the app is packaged for windows using electron-forge make the build completes successfully. But while running the packaged app Cannot find module X is thrown. The folder ./out/app/resources/app/node_modules is empty. Also the package.json ./out/app/resources/app/package.json looks as follows.

  "name": "my-app",
  "productName": "my-app",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": ".webpack/main",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\""
  },
  "keywords": [],
  "author": {
    "name": "",
    "email": ""
  },
  "license": "MIT",
  "config": {},
  "dependencies": {},
  "devDependencies": {},
  "optionalDependencies": {},
  "peerDependencies": {}
}

None of the dependencies in the source package.json made it to the packaged app.

1 Answers

Try this

cd "my-app"

:: install dependency into your node_modules and update your package.json
npm install your-dependency --save-prod
npm run make
Related