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

Webpack 5 polyfills #199

Closed
steveoh opened this issue Sep 10, 2021 · 6 comments
Closed

Webpack 5 polyfills #199

steveoh opened this issue Sep 10, 2021 · 6 comments

Comments

@steveoh
Copy link

steveoh commented Sep 10, 2021

Because of webpack 5 removing polyfills this library no longer works with the electron forge starter project.

I have been able to polyfill everything except for fs via the resolve.fallback webpack config. fs is imported from conf, electron, and path-exists.

resolve: {
  fallback: {
    assert: require.resolve('assert/'),
    crypto: require.resolve('crypto-browserify'),
    os: require.resolve('os-browserify/browser'),
    path: require.resolve('path-browserify'),
    stream: require.resolve('stream-browserify'),
    util: require.resolve('util'),
  },
},
Electron Forge was terminated:
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in '.../node_modules/atomically/dist/utils'
Did you mean './fs'?

I've tried the resolve.preferRelative: true, but it gives the same issue without the did you mean text.

Module not found: Error: Can't resolve 'fs' in '.../node_modules/conf/dist/source'

I'm not quite sure how to polyfill fs and if I should have to. What thoughts do folks have on this?

This stack overflow question has some answers about using window.require but I'm not sure how that can be possible with this projects dependencies.

Thanks in advance!

refs #191

@steveoh
Copy link
Author

steveoh commented Sep 10, 2021

inside my main.js it appear there is access to fs. Learning more about electron might be my issue.

const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const Store = require('electron-store');

const store = new Store();

ipcMain.handle('loadContent', (e) => {
  return store.get('config.key');
});

ipcMain.on('saveContent', (e, content) => {
  store.set('config.key', content);
});

This works.

@mikeliao97
Copy link

@steveoh were you able to install it? curious, same problem. :)

@steveoh
Copy link
Author

steveoh commented Oct 14, 2021

Yes, our issue was with the misunderstanding of where the node code was allowed to run. Using the ipc bridge to a main process allows this to work properly.

@sahil-liscio
Copy link

I have the same issue and I'm not sure how @steveoh solved it. Do i need to have node integration enabled? I still get the error that I need the fs module, if I set fs; false in the fallback then I get another error fs.existsFileSync doesnt exist.

@pjoulot
Copy link

pjoulot commented Jan 2, 2023

I also tried to use a boiler template: https://github.com/electron-react-boilerplate/electron-react-boilerplate
And impossible to make this library work with it :(

So I gave up and went for a custom implementation, but would love to replace my custom code with this package if someone finds a solution.

@sintanial
Copy link

See #259 (comment)

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

No branches or pull requests

5 participants