Closed sbowler closed 2 weeks ago
There is some discussion of a similar issue at https://github.com/microsoft/node-api-dotnet/issues/264#issuecomment-2042115327
I think the code could be changed to use non-dynamic requires, it would just be more verbose.
I thought that as well, but it is a bit different or potentially a different solution dealing with Electron.
I think perhaps a switch statement to include the correct library based on the different variables might work better, but as you said would be much more verbose.
I have a NodeJs webserver that currently utilizes Webpack 5.75.0. Due to the way this library dynamically requires/imports the needed dll file, I receive a warning from Webpack
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/node-api-dotnet/init.js
@ ./node_modules/node-api-dotnet/index.js 1:19-36
This ends up with a runtime error when I try to require node-api-dotnet
An unknown error occurred: Error: Cannot find module '....WebServer/win-x64/Microsoft.JavaScript.NodeApi.node'
From what I've read it sounds like it's generally bad practice to dynamically require files since it can cause issues like this, though I'm not sure what a better approach would be. I've been trying to figure out a way to work around the issue and didn't see anything in your documentation or tracked issues about this. Any help would be appreciated.