Skip to content

Webpack polyfills for Node.js #6

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

Closed
MCurran16 opened this issue Aug 29, 2021 · 5 comments
Closed

Webpack polyfills for Node.js #6

MCurran16 opened this issue Aug 29, 2021 · 5 comments

Comments

@MCurran16
Copy link

MCurran16 commented Aug 29, 2021

When you install modules that use native nodejs modules (path, fs, os, crypto, etc.), I run npm run start and get:

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

I'm trying to use the npm package: electron-settings

Have you run into this at all?

@aadiene
Copy link
Member

aadiene commented Aug 31, 2021

Regarding the package you want to install, last version of electron-settings (from 2020) may not be compatible with webpack 5.

I would like to help but first could you please give more details about how to reproduce.
Dont forget to mention your node/npm/ngcli versions.

@MCurran16
Copy link
Author

I am currently using this version of electron-settings. But yes, this is not compatible with Webpack 5.

Versions:
Angular CLI: 12.2.0
Node: 16.6.1
Package Manager: npm 7.20.3
OS: darwin x64

I'm trying to use this class:

import { StorageEngine } from '@ngxs/storage-plugin';
import SettingsStorage from 'electron-settings';

class ElectronStorage implements StorageEngine {

  public get length(): number {
    try {
      return SettingsStorage.keysSync().length;
    } catch (err) {
      return 0;
    }
  }

  public setItem(key: string, data: string): void {
    try {
      SettingsStorage.setSync({ [key]: data });
    } catch (err) {
      console.error('Error: Failed to set key: ', key);
      console.error(err);
    }
  }

  public getItem(key: string): any {
    try {
      return SettingsStorage.getSync(key);
    } catch (err) {
      console.error('Error: Failed to get key: ', key);
      console.error(err);
    }
  }

  public removeItem(key: string): void {
    try {
      SettingsStorage.unsetSync(key);
    } catch (err) {
      console.error('Error: Failed to unset key: ', key);
      console.error(err);
    }
  }

  public clear(): void {
    try {
      SettingsStorage.unsetSync();
    } catch (err) {
      console.error('Error: Failed to unset all keys');
      console.error(err);
    }
  }

  public getAllKeys(): string[] {
    try {
      return SettingsStorage.keysSync();
    } catch (err) {
      console.error('Error: Failed to get all keys');
      console.error(err);
      return [];
    }
  }
}

const storage = new ElectronStorage();
export {
  storage,
  ElectronStorage,
}

@MCurran16
Copy link
Author

I have tried:

  • adding this plugin: node-polyfill-webpack-plugin
  • adding paths in tsconfig compilerOptions

angular/angular-cli#20819

@aadiene
Copy link
Member

aadiene commented Oct 19, 2021

Hi @MCurran16,
I've successfully installed electron-settings (Node 16.11.1 / npm 7.24.2) by just following the readme and so with no polyfill at all. Feel free to clone this branch if you want to see changes and test it on your machine. Please let me know if you are still experiencing any issue.
Sorry for the late answer by the way (day work and stuff)

@aadiene
Copy link
Member

aadiene commented Apr 5, 2022

This issue was closed because it has been open for more than 30 days with no activity.

@aadiene aadiene closed this as completed Apr 5, 2022
@sourcygen sourcygen locked as resolved and limited conversation to collaborators Apr 8, 2022
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

2 participants