electron-remote icon indicating copy to clipboard operation
electron-remote copied to clipboard

Webpack support - don't use require.resolve(), allow user to use it if necessary

Open aguynamedben opened this issue 6 years ago • 9 comments

The README and in-code comment instructs users they may need to use require.resolve() to provide the correct path to requireTaskPool.

This is a problem for Webpack users because Webpack rewrites require.resolve().

Removing require.resolve() enables Webpack users to use electron-remote.

I'm not sure, but I think for some users who implicitly depend on the current behavior of electron-remote require.resolve()-ing for them, this may be a breaking change.

Here is an example that integrates electron-remote with electron-react-boilerplate project, which uses Webpack to produce the main process and renderer code: https://github.com/aguynamedben/electron-react-boilerplate/pull/1

Before making this change, I would run into the problem documented here: https://github.com/chentsulin/electron-react-boilerplate/issues/1587

Please let me know if there is a better way to fix this. From what I can tell, require.resolve() (from Node) is overwritten by Webpack.

aguynamedben avatar Jun 15 '18 00:06 aguynamedben

Related issues in this repo: https://github.com/electron-userland/electron-remote/pull/34 https://github.com/electron-userland/electron-remote/pull/26

aguynamedben avatar Jun 15 '18 00:06 aguynamedben

The core of the issue here (from what I can tell) is that require.resolve() behaves differently in Webpack than it does in Node.js. This comment nails it: https://github.com/webpack/webpack/issues/1554#issuecomment-158679844

This doesn't work.

require.resolve returns the module identifier according to CommonJS. In node.js this is the filename. In webpack this is a number.

I think this means any Node.js/Electron library that uses require.resolve() isn't going to play nicely with Webpack. :/

aguynamedben avatar Jun 15 '18 01:06 aguynamedben

Development note: when npm/yarn linking, be sure to ./build.sh the code after making changes. And with the electron-react-boilerplate project, electron-remote should be added to app/package.json, not package.json, and you should yarn link against app/package.json! (it's easy to accidentally yarn link to the wrong set of dependencies).

aguynamedben avatar Jun 15 '18 01:06 aguynamedben

Hi,

i'm using web pack and i doesn't can use electron-remote. in which version is this feather?

How i can use it in beta?

bitsmakerde avatar Jul 01 '18 16:07 bitsmakerde

i am also getting this issue.

Dolaned avatar Aug 09 '18 14:08 Dolaned

please, accept

gen4sp avatar Sep 23 '18 23:09 gen4sp

Might this workaround the issue within the lib? Comment

uholland avatar Feb 27 '19 21:02 uholland

Please accept this PR

vherus avatar Mar 19 '19 13:03 vherus

What's left to accept this?

vladejs avatar Apr 09 '19 12:04 vladejs