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
191 stars 62 forks source link

GCM register has failed #13

Closed RaimisJ closed 6 years ago

RaimisJ commented 6 years ago

Hi,

Works as expected in development. However, if I package it using electron-packager, I get this error (on ipcRenderer.send(START_NOTIFICATION_SERVICE, 'correct id'))

Register request has failed with Error=PHONE_REGISTRATION_ERROR Retry... 1 <retries 5 times, then> Register request has failed with Error=PHONE_REGISTRATION_ERROR PUSH_RECEIVER:::Error while starting the service Error: GCM register has failed

What could be the problem?

RaimisJ commented 6 years ago

The problem is with webpack - it does not copy .proto files and also when UglyfyJS is applied somehow the code stops working.

prescindivel commented 6 years ago

Hey @RaimisJ, how to fix this?

Thanks.

RaimisJ commented 6 years ago

In my case, this problem entirely depended on my configuration:

  1. In my configuration I had to swap "webpack.optimize.UglifyJsPlugin" with "uglifyjs-webpack-plugin", as the former produces unexpected results.
  2. Also, my configuration produces single electron.js file while packing, but it does not bundle proto files. So I copy them myself: shell.cp(path.join(__dirname, '../node_modules/push-receiver/src/client/mcs.proto'), targetPath) shell.cp(path.join(dirname, '../node_modules/push-receiver/src/gcm/android_checkin.proto'), targetPath) shell.cp(path.join(dirname, '../node_modules/push-receiver/src/gcm/checkin.proto'), targetPath)
prescindivel commented 6 years ago

Thanks @RaimisJ

ream88 commented 6 years ago

I'm also encountering this problem, however my .proto files are properly copied to my build dir. It works perfectly when compiled with webpack, it however fails with the same error mentioned above when packing the code with electron-builder. Any ideas?

ream88 commented 6 years ago

@RaimisJ what is targetPath in your config? The output folder of webpack?

RaimisJ commented 6 years ago

@ream88 in the end, I ended up using not bundled node_modules folders. Only then it works correctly in all cases.

ream88 commented 6 years ago

@RaimisJ Yeah, not using webpack and bundling the files helped! However now I need more and more features provided via webpack like for example its DefineWebpack plugin, and I'm stuck again 😞

MatthieuLemoine commented 5 years ago

@ream88 I think you have the issue as #32

benoist commented 4 years ago
process.env.NODE_ENV = process.env.NODE_ENV || "production"

const CleanWebpackPlugin = require("clean-webpack-plugin")
const CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
  module: {
    rules: [
      {
        test: /\.(m?js|node)$/,
        parser: {amd: false},
        use: {
          loader: "@zeit/webpack-asset-relocator-loader",
          options: {
            outputAssetBase: "build",
          },
        },
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: "babel-loader",
      },
    ],
  },
  entry: "./main.js",
  plugins: [
    new CleanWebpackPlugin(["dist", "build"]),
    new CopyWebpackPlugin([
      {from: "node_modules/push-receiver/src/mcs.proto", to: "build"},
      {from: "node_modules/push-receiver/src/gcm/android_checkin.proto", to: "build"},
      {from: "node_modules/push-receiver/src/gcm/checkin.proto", to: "build"},
    ]),
  ],
  output: {
    path: __dirname,
    filename: "main-packaged.js",
  },
  node: {
    __dirname: false,
    __filename: false,
  },
  target: "electron-main",
  mode: "production",
  stats: {
    colors: true,
    children: false,
    chunks: false,
    modules: false,
  },
}

This works for me