Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't work with webpack #3

Closed
steambap opened this issue Sep 24, 2016 · 19 comments
Closed

doesn't work with webpack #3

steambap opened this issue Sep 24, 2016 · 19 comments

Comments

@steambap
Copy link

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
@sindresorhus
Copy link
Owner

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

@ghost
Copy link

ghost commented Sep 26, 2016

@steambap Not sure if the fix I used will work for you, but adding this into your webpack.config may help:

externals: [{
  'electron-config': 'electron-config'
}]

@jaxgeller
Copy link

Sorry to comment after being closed. Adding the externals like above and output.libraryTarget= 'commonjs2' seems to do the trick. I hope this helps.

@danielnieto
Copy link

danielnieto commented Oct 6, 2016

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;

@akashnimare
Copy link

@jaxgeller @jamesmacfie8i this works perfectly -

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

@komplexb
Copy link

komplexb commented Dec 14, 2016

Hey @danielnieto was there a particular issue you were trying to solve why you have all those other externals? I tried it but now I get Uncaught Error: Cannot find module 'require("electron")'. Any idea what might be wrong here?

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")'
},

@komplexb
Copy link

komplexb commented Dec 14, 2016

Hey @jamesmacfie8i I tried #3 (comment) but now I get Uncaught ReferenceError: electron is not defined, any thoughts?

Also tried #3 (comment) but now I get Uncaught Error: Cannot find module 'electron-config' care to lend a hand @akashnimare?

@komplexb
Copy link

Hey @steambap did you get #3 (comment) solved?

@safinn
Copy link

safinn commented May 9, 2017

@komplexb When I exclude this module in the webpack config I also get the issue with electron cannot be found. Did you get this working?

@komplexb
Copy link

@sallar
Copy link

sallar commented Jul 2, 2017

For people who come here, you have to add conf to the externals array as well.

@nicolabortignon
Copy link

@sallar would you please list exactly the steps you need to take to make this lib working with webpack?

@sallar
Copy link

sallar commented Jul 24, 2017

@nicolabortignon In your webpack config:

module.exports = {
  ...
  externals: ['conf']
};

More info: https://webpack.js.org/configuration/externals/

@nicolabortignon
Copy link

@sallar sorry, but not 100% sure here.

I'm using this boilerplate: https://github.com/chentsulin/electron-react-boilerplate

And in this file: https://github.com/chentsulin/electron-react-boilerplate/blob/master/webpack.config.base.js

at line 10, I did replace with:
externals: ['conf', Object.keys(externals || {})] ,

This doesn't work. Any idea why?

@ClementParis016
Copy link

output.libraryTarget and externals aren't of any help, I did look at a few related issues but it gets quite complicated, I've no idea how this can be solved...

@alexbrazier
Copy link

I got this working by adding electron-store to externals. externals: ['electron-store']

@nicolabortignon Using the boilerplate you can change: import { dependencies as externals } from './app/package.json'; to import { dependencies as externals } from './package.json'; to make it work

@sgehrman
Copy link

sgehrman commented Sep 5, 2017

same problem, nothing works, why can't this work with webpack?

@mdings
Copy link

mdings commented Nov 5, 2017

@sgehrman are you sure you're using the right package name? If you did a recent install then the above package names should be renamed to electron-store, like so:

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

Repository owner deleted a comment from framerate Nov 8, 2017
Repository owner locked and limited conversation to collaborators Nov 8, 2017
@sindresorhus
Copy link
Owner

Please show your frustration on the webpack issue tracker: webpack/webpack#196

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests