electron-store: doesn't work with webpack

If I require this module in webpack, it will break webpack because of this line const parentDir = path.dirname(module.parent.filename);

Is there any way to make it work webpack, maybe refer to the global.module instead of just module?

I’m using:

  • electron-config: 0.2.1
  • electron: 1.4.1
  • webpack: 1.13.2

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

@jaxgeller @jamesmacfie8i this works perfectly -

module.exports = {
    target: 'node',
    externals: [{
      'electron-config': 'electron-config'
    }],
    output: {
        libraryTarget : 'commonjs2'
    }
};

It’s the inverse: Webpack doesn’t work with this module. Open an issue on the Webpack repo.

solutions above didn’t work for me, but I did this:

externals: [{ 'electron-config': 'require("electron-config")' }]

I didn’t have to add anything else, if it’s useful here’s my webpack.config.js (I’m my project I’m using vue.js):

/* eslint strict: 0 */
'use strict';

const path = require('path');
const webpack = require('webpack');

let options ={
watch: true,
target: "electron",
externals: {
    'electron': 'require("electron")',
    'net': 'require("net")',
    'remote': 'require("remote")',
    'shell': 'require("shell")',
    'app': 'require("app")',
    'ipc': 'require("ipc")',
    'fs': 'require("fs")',
    'buffer': 'require("buffer")',
    'system': '{}',
    'file': '{}',
    'electron-config': 'require("electron-config")'
},
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loaders: [],
      exclude: /node_modules/,
    }]
  },
  output: {
    path: path.join(__dirname, 'app/build'),
    publicPath: path.join(__dirname, 'src'),
    filename: 'bundle.js',
  },
  resolve: {
    extensions: ['', '.js', '.jsx'],
    packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main'],
    alias: {vue: 'vue/dist/vue.js'}
  },
  entry: [
    './app/js/index',
  ],
  debug: true,

};

module.exports = options;