MatthieuLemoine / electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
194 stars 68 forks source link

checkin.proto not found #51

Open anilv0001 opened 5 years ago

anilv0001 commented 5 years ago

hey I m getting this error --> ENOENT, checkin.proto not found in /Applications/ElectronReact.app/Contents/Resources/app.asar in release build notification.

MatthieuLemoine commented 5 years ago

Did you try https://github.com/MatthieuLemoine/electron-push-receiver/issues/27?

anilv0001 commented 5 years ago

Yes, I tried #27 but still getting the same error, copy-webpack-plugin module copies file successfully to the required directory but it gets deleted as build started.

MatthieuLemoine commented 5 years ago

Can you share your Webpack config file & release scripts?

anilv0001 commented 5 years ago

webpack.config.base.js

/**
 * Base webpack config used across other specific configs
 */

import path from 'path';
import webpack from 'webpack';
import fs from 'fs';
import { dependencies as externals } from '../app/package.json';
import { dependencies as possibleExternals } from '../package.json';
const CopyWebpackPlugin = require('copy-webpack-plugin');
const fromCopy = 'node_modules/push-receiver/src/gcm/checkin.proto';
const toCopy = path.resolve(__dirname, '..', 'release', 'mac', 'ElectronReact.app', 'Contents', 'Resources');
console.log({
  from: fromCopy,
  to: toCopy
});

// Find all the dependencies without a `main` property and add them as webpack externals
function filterDepWithoutEntryPoints(dep: string): boolean {
  // Return true if we want to add a dependency to externals
  try {
    // If the root of the dependency has an index.js, return true
    if (
      fs.existsSync(path.join(__dirname, '..', `node_modules/${dep}/index.js`))
    ) {
      return false;
    }
    const pgkString = fs
      .readFileSync(require.resolve(`${dep}/package.json`))
      .toString();
    const pkg = JSON.parse(pgkString);
    const fields = ['main', 'module', 'jsnext:main', 'browser'];
    return !fields.some(field => field in pkg);
  } catch (e) {
    console.log(e);
    return true;
  }
}

export default {
  externals: [
    ...Object.keys(externals || {}),
    ...Object.keys(possibleExternals || {}).filter(filterDepWithoutEntryPoints)
  ],

  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            cacheDirectory: true
          }
        }
      }
    ]
  },

  output: {
    path: path.join(__dirname, '..', 'app'),
    // https://github.com/webpack/webpack/issues/1114
    libraryTarget: 'commonjs2'
  },

  /**
   * Determine the array of extensions that should be used to resolve modules.
   */
  resolve: {
    extensions: ['.js', '.jsx', '.json'],
    modules: [path.join(__dirname, '..', 'app'), 'node_modules']
  },

  plugins: [
    new webpack.EnvironmentPlugin({
      NODE_ENV: 'production'
    }),

    new webpack.NamedModulesPlugin(),

    new CopyWebpackPlugin([
      {
        from: fromCopy,
        to: toCopy,
      }
    ]),
  ]
};

package.json

{
  "name": "electron-react-boilerplate",
  "productName": "ElectronReact",
  "version": "0.16.0",
  "description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development",
  "scripts": {
    "build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",
    "build-dll": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config ./configs/webpack.config.renderer.dev.dll.js --colors",
    "build-e2e": "cross-env E2E_BUILD=true yarn build",
    "build-main": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config ./configs/webpack.config.main.prod.js --colors",
    "build-renderer": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config ./configs/webpack.config.renderer.prod.js --colors",
    "dev": "cross-env START_HOT=1 node -r babel-register ./internals/scripts/CheckPortInUse.js && cross-env START_HOT=1 yarn start-renderer-dev",
    "electron-rebuild": "electron-rebuild --parallel --force --types prod,dev,optional --module-dir app",
    "flow": "flow",
    "flow-typed": "rimraf flow-typed/npm && flow-typed install --overwrite || true",
    "lint": "cross-env NODE_ENV=development eslint --cache --format=pretty .",
    "lint-fix": "yarn --silent lint --fix; exit 0",
    "lint-styles": "stylelint --ignore-path .eslintignore '**/*.*(css|scss)' --syntax scss",
    "lint-styles-fix": "yarn --silent lint-styles --fix; exit 0",
    "package": "yarn build && electron-builder build --publish never",
    "package-all": "yarn build && electron-builder build -mwl",
    "package-ci": "yarn postinstall && yarn build && electron-builder --publish always",
    "package-linux": "yarn build && electron-builder build --linux",
    "package-win": "yarn build && electron-builder build --win --x64",
    "postinstall": "node -r babel-register internals/scripts/CheckNativeDep.js && yarn flow-typed && yarn build-dll && electron-builder install-app-deps package.json",
    "postlint-fix": "prettier --ignore-path .eslintignore --single-quote --write '**/*.{*{js,jsx,json},babelrc,eslintrc,prettierrc,stylelintrc}'",
    "postlint-styles-fix": "prettier --ignore-path .eslintignore --single-quote --write '**/*.{css,scss}'",
    "precommit": "lint-staged",
    "prestart": "yarn build",
    "start": "cross-env NODE_ENV=production electron ./app/",
    "start-main-dev": "cross-env HOT=1 NODE_ENV=development electron -r babel-register ./app/main.dev.js",
    "start-renderer-dev": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack-dev-server/bin/webpack-dev-server --config configs/webpack.config.renderer.dev.js",
    "test": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 node --trace-warnings -r babel-register ./internals/scripts/RunTests.js",
    "test-all": "yarn lint && yarn flow && yarn build && yarn test && yarn build-e2e && yarn test-e2e",
    "test-e2e": "node -r babel-register ./internals/scripts/CheckBuiltsExist.js && cross-env NODE_ENV=test testcafe electron:./app ./test/e2e/HomePage.e2e.js",
    "test-e2e-live": "node -r babel-register ./internals/scripts/CheckBuiltsExist.js && cross-env NODE_ENV=test testcafe-live electron:./app ./test/e2e/HomePage.e2e.js",
    "test-watch": "yarn test --watch"
  },
  "browserslist": "electron 1.6",
  "lint-staged": {
    "*.{js,jsx}": [
      "cross-env NODE_ENV=development eslint --cache --format=pretty",
      "prettier --ignore-path .eslintignore --single-quote --write",
      "git add"
    ],
    "{*.json,.{babelrc,eslintrc,prettierrc,stylelintrc}}": [
      "prettier --ignore-path .eslintignore --parser json --write",
      "git add"
    ],
    "*.{css,scss}": [
      "stylelint --ignore-path .eslintignore --syntax scss --fix",
      "prettier --ignore-path .eslintignore --single-quote --write",
      "git add"
    ],
    "*.{yml,md}": [
      "prettier --ignore-path .eslintignore --single-quote --write",
      "git add"
    ]
  },
  "main": "./app/main.prod.js",
  "build": {
    "productName": "ElectronReact",
    "appId": "org.develar.ElectronReact",
    "asar": true,
    "asarUnpack": true,
    "extraFiles": true,
    "extraResources": true,
    "files": [
      "*.js",
      "build/**/*",
      "node_modules/**/*",
      "dist/**/*",
      "app.html",
      "main.prod.js",
      "main.prod.js.map",
      "package.json"
    ],
    "dmg": {
      "contents": [
        {
          "x": 130,
          "y": 220
        },
        {
          "x": 410,
          "y": 220,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "win": {
      "target": [
        "nsis",
        "msi"
      ]
    },
    "linux": {
      "target": [
        "deb",
        "rpm",
        "snap",
        "AppImage"
      ],
      "category": "Development"
    },
    "directories": {
      "buildResources": "resources",
      "output": "release"
    }
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/electron-react-boilerplate/electron-react-boilerplate.git"
  },
  "contributors": [
    {
      "name": "Vikram Rangaraj",
      "email": "vikr01@icloud.com",
      "url": "https://github.com/vikr01"
    },
    {
      "name": "Amila Welihinda",
      "email": "amilajack@gmail.com",
      "url": "https://github.com/amilajack"
    }
  ],
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues"
  },
  "keywords": [
    "electron",
    "boilerplate",
    "react",
    "redux",
    "flow",
    "sass",
    "webpack",
    "hot",
    "reload"
  ],
  "homepage": "https://github.com/electron-react-boilerplate/electron-react-boilerplate#readme",
  "jest": {
    "testURL": "http://localhost/",
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/internals/mocks/fileMock.js",
      "\\.(css|less|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json"
    ],
    "moduleDirectories": [
      "node_modules",
      "app/node_modules"
    ],
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    },
    "setupFiles": [
      "./internals/scripts/CheckBuiltsExist.js"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.6",
    "babel-jest": "^23.4.2",
    "babel-loader": "^7.1.5",
    "babel-plugin-add-module-exports": "^0.3.0",
    "babel-plugin-dev-expression": "^0.2.1",
    "babel-plugin-flow-runtime": "^0.17.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-es2015-classes": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-react-optimize": "^1.0.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "chalk": "^2.4.1",
    "concurrently": "^3.6.1",
    "connected-react-router": "^4.4.1",
    "cross-env": "^5.2.0",
    "cross-spawn": "^6.0.5",
    "css-loader": "^1.0.0",
    "detect-port": "^1.2.3",
    "electron": "^4.1.3",
    "electron-builder": "^20.39.0",
    "electron-devtools-installer": "^2.2.4",
    "electron-rebuild": "^1.8.2",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "enzyme-to-json": "^3.3.4",
    "eslint": "^5.2.0",
    "eslint-config-airbnb": "^17.0.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-formatter-pretty": "^1.3.0",
    "eslint-import-resolver-webpack": "^0.10.1",
    "eslint-plugin-compat": "^2.5.1",
    "eslint-plugin-flowtype": "^2.50.0",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-jest": "^21.18.0",
    "eslint-plugin-jsx-a11y": "6.1.1",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-react": "^7.10.0",
    "eslint-plugin-testcafe": "^0.2.1",
    "fbjs-scripts": "^0.8.3",
    "file-loader": "^1.1.11",
    "flow-bin": "^0.77.0",
    "flow-runtime": "^0.17.0",
    "flow-typed": "^2.5.1",
    "husky": "^0.14.3",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^23.4.2",
    "lint-staged": "^7.2.0",
    "mini-css-extract-plugin": "^0.4.1",
    "node-sass": "^4.9.2",
    "optimize-css-assets-webpack-plugin": "^5.0.0",
    "prettier": "^1.14.3",
    "react-test-renderer": "^16.4.1",
    "redux-logger": "^3.0.6",
    "rimraf": "^2.6.2",
    "sass-loader": "^7.0.3",
    "sinon": "^6.1.4",
    "spectron": "^5.0.0",
    "style-loader": "^0.21.0",
    "stylelint": "^9.4.0",
    "stylelint-config-prettier": "^4.0.0",
    "stylelint-config-standard": "^18.2.0",
    "testcafe": "^0.21.1",
    "testcafe-browser-provider-electron": "^0.0.6",
    "testcafe-live": "^0.1.3",
    "testcafe-react-selectors": "^3.0.0",
    "uglifyjs-webpack-plugin": "1.2.7",
    "url-loader": "^1.0.1",
    "webpack": "^4.16.3",
    "webpack-bundle-analyzer": "^2.13.1",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5",
    "webpack-merge": "^4.1.3",
    "yarn": "^1.9.2",
    "axios": "^0.18.0",
    "@material-ui/core": "latest",
    "@material-ui/icons": "latest",
    "promise": "8.0.1",
    "react-big-calendar": "^0.19.2",
    "react-datepicker": "^2.8.0",
    "react-select": "3.0.4",
    "moment": "^2.24.0"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.2.0",
    "classnames": "^2.2.6",
    "copy-webpack-plugin": "^5.0.4",
    "devtron": "^1.4.0",
    "electron-debug": "^2.0.0",
    "electron-download-manager": "^2.1.2",
    "electron-push-receiver": "^2.1.3",
    "fs-extra": "latest",
    "hidefile": "^3.0.0",
    "history": "^4.7.2",
    "pure-react-carousel": "^1.22.0",
    "react": "^16.4.1",
    "react-alice-carousel": "^1.15.3",
    "react-dom": "^16.4.1",
    "react-file-viewer": "^1.1.0",
    "react-hot-loader": "^4.3.4",
    "react-pdf-js": "^3.0.3",
    "react-pdf-js-infinite": "^1.2.0",
    "react-redux": "^5.0.7",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-slick": "^0.25.2",
    "react-toastify": "^5.3.2",
    "redux": "^4.0.0",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "slick-carousel": "^1.8.1",
    "source-map-support": "^0.5.6",
    "styled-components": "^5.0.0-beta.8"
  },
  "devEngines": {
    "node": ">=7.x",
    "npm": ">=4.x",
    "yarn": ">=0.21.3"
  }
}

webpack.config..zip

anilv0001 commented 5 years ago

Hey finally its working, there was a configuration issue thanks for your help

MatthieuLemoine commented 5 years ago

@anilv0001 Can you share your fix?

adouglass commented 3 years ago

To solve this problem when using electron-builder, I had to use both the CopyWebpackPlugin described in #27 and specifically instruct the builder to place the .proto files in the .asar at the root, by adding this entry to my package.json files:

"files": [ "main.prod.js", "app.html", { "from":"dist/", "to":"./", "filter": [ "*.proto" ] } ]

codemeall commented 3 years ago

@adouglass I added

"files": [ "main.prod.js", "app.html", { "from":"dist/", "to":"./", "filter": [ "*.proto" ] } ]

to my package.json like this

"name": "-electron-v1", "description": "electron version", "author": "cdmn", "version": "0.1.0", "private": true, "files": [ "index.js", "index.html", { "from":"dist_electron/", "to":"./", "filter": [ "*.proto" ] } ], "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "build:win": "vue-cli-service electron:build --windows", "build:mac": "vue-cli-service electron:build --macos", "build:lin": "vue-cli-service electron:build --linux", "electron:build": "vue-cli-service electron:build", "electron:serve": "vue-cli-service electron:serve", "electron:generate-icons": "electron-icon-builder --input=./public/icon.png --output=build --flatten", "postinstall": "electron-builder install-app-deps", "postuninstall": "electron-builder install-app-deps" },

it is not working.

hongky-1994 commented 3 years ago

Thank to @adouglass and @MatthieuLemoine , it finally worked, Step 1. I add copy-webpack-plugin and config webpack.config.base.js

import CopyPlugin from "copy-webpack-plugin"
...
 plugins: [
    new CopyPlugin({
      patterns: [
        {from: "node_modules/push-receiver/src/mcs.proto", to: "src/dist/mcs.proto"},
        {from: "node_modules/push-receiver/src/gcm/android_checkin.proto", to: "src/dist/android_checkin.proto"},
        {from: "node_modules/push-receiver/src/gcm/checkin.proto", to: "src/dist/checkin.proto"},
      ],
    }),
  ],
...

Step 2. I config package.json (not in src) like @adouglass

"build": {
     ...
    "files": [
       ...,
      { "from":"dist/", "to":"./", "filter": [ "*.proto" ] }
    ],
}

Hope this help !

Additional: my script package, my temporary build is in src/dist before electron-build. "package:never": "rm -rf src/dist && yarn build && electron-builder build --publish never",