How to make webpack ignore a require to a mising file in a npm module?

61
February 14, 2021, at 4:40 PM

When bundling my project with webpack, I encountered an error message indicating that a .node file required in one of my npm package does not exist.

After searching for a while, I believe that the missing file is actually not used by the package because

  1. it is required conditionally and
  2. the condition never happens

In conclusion, it should be safe to ignore the require statement. However, since the package is not written by me, I cannot simply remove that line of code. (a package upgrade in some other day will revert it)
How can I instruct webpack to ignore that require?

I have tried the following things:

  1. Exclude file (another stackoverflow Q&A). Not sure if I got the idea of this answer. I excluded the file in one of the module rules but webpack still tried to load the missing file. I guess exclude merely prevents the file getting transformed but not loaded.
  2. Externalize file (also a stackoverflow Q&A). Adding this line of code to my webpack config externals: /path\/to\/missing\/file$/i, I encountered a different error message when running webpack: ERROR in main.js from Terser. Unexpected token: expand (...). I got no idea how to solve it.
READ ALSO
Dynamically loading property value from active list of profiles and set the value in configuration XML file

Dynamically loading property value from active list of profiles and set the value in configuration XML file

I have a spring bath application which contains a batch configurationI want to dynamically load profile based upon the environemnt variable parameter of active profile list

75
WorkManager using setForegroundAsync() with ListenableWorker

WorkManager using setForegroundAsync() with ListenableWorker

A very useful guide and code snippet is provided for using setForegroundAsync() for a long-running worker in the context of a Worker in WorkManager

78
Update XML with an SQL query

Update XML with an SQL query

Let's say we have the following XML file:

77