bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
328 stars 85 forks source link

Tslib not found - custom webpack config on serve #218

Closed breadberry-prime closed 1 year ago

breadberry-prime commented 1 year ago

Bug Description:

When adding the tslib module to the preload script in an Electron application using the contextBridge, an error occurs indicating that tslib is not found.

Steps to Reproduce:

Create a new Electron application. Add the following code snippet to the preload script file (e.g., main.preload.ts):

contextBridge.exposeInMainWorld('electronAPI', {
  getAudioSources: async () => {
    try {
      return await desktopCapturer.getSources({ types: ['window', 'screen'] });
    } catch (error) {
      console.error('Error capturing sources: ', error);
      throw error;
    }
  },
});

Run the Electron application and observe the error related to tslib not being found.

Expected Behavior: The application should successfully bundle the tslib module and load it in the Electron preload script, allowing the code to run without errors.

Actual Behavior: The application throws an error indicating that tslib is not found when attempting to run the Electron preload script.

Screenshots

image

Desktop (please complete the following information):

 Node : 18.16.0
   OS   : darwin arm64
   yarn : 1.22.19

   nx                      : 15.9.2
   @nrwl/js                : 15.9.2
   @nrwl/jest              : 15.9.2
   @nrwl/linter            : 15.9.2
   @nrwl/workspace         : 15.9.2
   @nrwl/angular           : 15.9.2
   @nrwl/cli               : 15.9.2
   @nrwl/cypress           : 15.9.2
   @nrwl/devkit            : 15.9.2
   @nrwl/eslint-plugin-nx  : 15.9.2
   @nrwl/tao               : 15.9.2
   @nrwl/web               : 15.9.2
   @nrwl/webpack           : 15.9.2
   @nrwl/nx-cloud          : 15.3.5
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @ngrx/component-store : 15.4.0
   @ngrx/effects         : 15.4.0
   @ngrx/entity          : 15.4.0
   @ngrx/router-store    : 15.4.0
   @ngrx/store           : 15.4.0
   @ngrx/store-devtools  : 15.4.0
   @ngrx/schematics      : 15.3.0
   nx-electron           : 15.0.0

Additional Context: I spent approximately 4 hours debugging this issue, which included reinstalling the entire project and creating a new NX workspace with a blank React app to isolate the problem. Despite installing tslib version ^2.4.1 as recommended by the nx-electron app, the error persists. I have followed all the necessary steps, and the issue seems to be specific to the interaction between nx-electron and tslib.

customWebpackConfig serve The nx-electron plugin exhibits a behavior where the custom webpack configuration, provided through the customWebpackConfig option, successfully works for the build command but does not have any effect on the serve command. This raises uncertainty regarding whether this behavior is intended or a potential bug. Additionally, there is a question about the possibility of modifying the webpack configuration specifically for the serve command.

The current state suggests that the serve command in the nx-electron plugin might not be utilizing the custom webpack configuration, despite it being specified. This issue requires further investigation to determine the root cause and find a resolution.

Any assistance or guidance from the community in resolving this matter would be highly appreciated. <3

bennymeg commented 1 year ago

Hi,

  1. You should be able to pass build option like webpackConfig when you serve your app with the buildTargetOptions option.
  2. Can you please clarify, the issue occurs only when you serve the app, or both when serving / building?