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

No such file or directory build\checkin.proto #27

Closed redplane closed 5 years ago

redplane commented 6 years ago

Hi,

I'm using electron-push-receiver version 2.0.0. When I use ipcRenderer.send(START_NOTIFICATION_SERVICE, senderId); in my renderer process, there is an error in my console window says that; PUSH_RECEIVER:::Error while starting the service { Error: ENOENT: no such file or directory, open '<my path>\build\checkin.proto'

What wrong have I done ?

Thank you,

MatthieuLemoine commented 6 years ago

Are you using a bundler like webpack ?

redplane commented 6 years ago

Yes, I'm using web 4.12

anboia commented 5 years ago

I am having the same issue, but only when I open the app after installation. It happens when the gcm/index.js tries to access the proto file: root = await protobuf.load(path.join(__dirname, 'checkin.proto'));

The app tries to acess the file in the app.asar file: C:\Users\User\AppData\Local\Programs\MyApp\resources\app.asar

I am guessing we need to specify somewere in webpack that we want to add that .proto file in the resource.

MatthieuLemoine commented 5 years ago

You can use https://github.com/webpack-contrib/copy-webpack-plugin to copy the .proto files

robmontesinos commented 5 years ago

Hi @MatthieuLemoine , thank you for a hugely valuable library. Is there any chance that you could post some sample code using copy-webpack-plugin to copy the .proto files? Thank you

robmontesinos commented 5 years ago

I tried the following web pack config using vue.config.js - using electron-builder and @vue/cli and am still receiving the above error regarding 'checkin.proto' not found in 'dist_electron'

const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
    configureWebpack: {
        externals: {
            'any-promise': 'Promise'
        },
        plugins: [
            new webpack.NormalModuleReplacementPlugin(/^any-promise$/, 'bluebird'),
            new CopyWebpackPlugin([
                {
                    from: 'node_modules/push-receiver/src/gcm/checkin.proto',
                    to: 'dist_electron/checkin',
                    toType: 'file'
                }
            ])
        ],
        optimization: {
            minimizer: [
                new TerserPlugin({
                    parallel: true,
                    terserOptions: {
                        compress: true,
                        mangle: true
                    }
                })
            ]
        }
    }
}
vinay3206 commented 4 years ago

@robmontesinos Are u able to solve this ?

Radzell commented 4 years ago

Anyone able to solve this

wanguolin commented 4 years ago

Having the same issue when I tried to use grpc in election with vue & vuetify.

I have tested all of the "webpack" related grpc loaders on the npm and none of them worked, perhaps I've made some mistake which I've not aware....either it shows ".proto file not found", or "Invalid package electon.asar" finally.

I believe the root cause is related to the proto file loading when webpack compiled the project, but even I configured the "CopyPlugin" in my vue.config.js, I still have problem to locate the proto file...

I worked 3 whole days and finally found this article which seems very close to my issue, really appreciate if any one could figure out how to config the CopyPlugin and load it after pack.

vinay3206 commented 4 years ago

I tried this and worked for me @wanguolin

const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
  /**
   * This is the main entry point for your application, it's the first file
   * that runs in the main process.
   */
  entry: "./src/index.js",
  // Put your normal webpack config below here
  module: {
    rules: require("./webpack.rules")
  },
  plugins: [new CopyWebpackPlugin([{ from: "src/grpc/proto", to: "proto" }])],
  resolve: {
    extensions: [".ts", ".js", ".json"]
  }
};

while using it I just use it as

import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";

const PROTO_PATH = `${__dirname}/proto/core.proto`;
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
});

const { core } = grpc.loadPackageDefinition(packageDefinition);

export default core;
wanguolin commented 4 years ago

Having the same issue when I tried to use grpc in election with vue & vuetify.

I have tested all of the "webpack" related grpc loaders on the npm and none of them worked, perhaps I've made some mistake which I've not aware....either it shows ".proto file not found", or "Invalid package electon.asar" finally.

I believe the root cause is related to the proto file loading when webpack compiled the project, but even I configured the "CopyPlugin" in my vue.config.js, I still have problem to locate the proto file...

I worked 3 whole days and finally found this article which seems very close to my issue, really appreciate if any one could figure out how to config the CopyPlugin and load it after pack.

I tried this and worked for me @wanguolin

const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
  /**
   * This is the main entry point for your application, it's the first file
   * that runs in the main process.
   */
  entry: "./src/index.js",
  // Put your normal webpack config below here
  module: {
    rules: require("./webpack.rules")
  },
  plugins: [new CopyWebpackPlugin([{ from: "src/grpc/proto", to: "proto" }])],
  resolve: {
    extensions: [".ts", ".js", ".json"]
  }
};

while using it I just use it as

import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";

const PROTO_PATH = `${__dirname}/proto/core.proto`;
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
});

const { core } = grpc.loadPackageDefinition(packageDefinition);

export default core;

Thanks for your answer, I put the configuration like yours in rendering process, is shows: "Uncaught Error: Invalid package ...\resources\electron.asar".

Now I've worked around this issue by using 'webpack-proto-loader' in main process with proto files in vue's 'public folder'.

anteeek commented 3 years ago

A little update since copy-webpack-plugin has changed:

plugins: [
    new CopyWebpackPlugin({ 
      patterns: [
        {
         // CHANGE NODE MODULES PATH TO WHERE ELECTRON IS INSTALLED. FOR MONOREPOS IT'S USUALLY ../../node_modules
          from: "./node_modules/**/*.proto", 
          to: "[name].[ext]",
        }
      ]
    })
  ],

this worked for me, while the previous response for some reason didn't

pragatijadhav commented 3 years ago

I have used copy-webpack-plugin, facing the same issue after generating an executable with electron-builder. Below is the code from my webpack file.

image

hieu-ht commented 2 years ago

For someone struggling when integrating this awesome package with your electron project is built with vue-cli-plugin-electron-builder, you need to use a custom webpack config build of the main process, not renderer process, this is vue-cli-plugin-electron-builder docs about that. You need to custom build config with chainWebpackMainProcess Here is my configuration at vue.config.js:

const { defineConfig } = require("@vue/cli-service");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = defineConfig({
  transpileDependencies: true,
  pluginOptions: {
    electronBuilder: {
      preload: "src/preload.ts",
      builderOptions: {
        appId: "...",
        publish: [
          {
            provider: "generic",
            url: "http://127.0.0.1:3005/",
          },
        ],
        mac: {
          category: "public.app-category.business",
          target: ["zip", "dmg"],
        },
        nsis: {
          oneClick: true,
          perMachine: false,
          runAfterFinish: true,
          allowElevation: true,
          deleteAppDataOnUninstall: true,
          menuCategory: true,
        },
        win: {
          target: [
            {
              target: "nsis",
              arch: ["x64"],
            },
          ],
          publisherName: "...",
          legalTrademarks: "...",
          verifyUpdateCodeSignature: false,
        },
      },
      /**
       * work around to fix this issue: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1647#issuecomment-1019400838
       * some resources is defined by url in css file can't be loaded on production build (urls start with app:///)
       * docs of package related to this issue: https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/configuration.html#changing-the-file-loading-protocol
       * */
      customFileProtocol: "./",
      externals: ["chokidar"],
      chainWebpackMainProcess: (config) => {
        // Chain webpack config for electron main process only
        config.plugin("copy").use(CopyWebpackPlugin, [
          {
            patterns: [
              {
                from: "node_modules/push-receiver/src/mcs.proto",
                to: "mcs.proto",
              },
              {
                from: "node_modules/push-receiver/src/gcm/android_checkin.proto",
                to: "android_checkin.proto",
              },
              {
                from: "node_modules/push-receiver/src/gcm/checkin.proto",
                to: "checkin.proto",
              },
            ],
          },
        ]);
      },
    },
  },
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import "@/assets/css/variables.scss";`,
      },
    },
  },
  configureWebpack: {
    // Webpack's configuration applied to web builds and the electron renderer process
    plugins: [
      new NodePolyfillPlugin(),
    ],
  },
});