<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
Using webpack in the electron js app I can't import native module libraries like <code class="notranslate">ffi-napi</code>, <code class="notranslate">ref-napi</code>, etc in my application. Libraries like those generally expects node's <code class="notranslate">__dirname</code> to set as global. Thus, setting <code class="notranslate">node: {__dirname: true}</code> would work in my app but in the <code class="notranslate">production</code> built it throws a runtime error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Error: No native build was found for platform=darwin arch=x64 runtime=electron abi=87 uv=1 libc=glibc node=14.16.0 electron=12.0.6 webpack=true"><pre class="notranslate"><code class="notranslate">Error: No native build was found for platform=darwin arch=x64 runtime=electron abi=87 uv=1 libc=glibc node=14.16.0 electron=12.0.6 webpack=true
</code></pre></div>
<p dir="auto">The same above error would throws if I change/remove <code class="notranslate">node:{__dirname: false}</code> or <code class="notranslate">node</code> property itself from the webpack config.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
I'm not sure on this whether its a bug or not. But to reproduce the scenario here's my example <a href="https://github.com/raviSussol/electron-webpack-native-module-example">repo</a> which can show the issue in more details. Basically,</p>
<h5 dir="auto">to reproduce an error</h5>
<ul dir="auto">
<li>start the app by <code class="notranslate">npm start</code></li>
<li>then an error would shown up</li>
</ul>
<h5 dir="auto">to get working</h5>
<ul dir="auto">
<li>change the <code class="notranslate">__dirname</code> to <code class="notranslate">true</code> in the <code class="notranslate">webpack.config.js</code> and again</li>
<li>start the app by <code class="notranslate">npm start</code></li>
<li>now it runs OK. To confirm if native module <code class="notranslate">ffi-napi</code>, <code class="notranslate">ref-napi</code> are working properly - goto View &gt; Toggle Developer Tools and in the console tab = <code class="notranslate">Add: 8</code></li>
</ul>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
If I need to set <code class="notranslate">node:{__dirname: true}</code> in this case (which works in the <code class="notranslate">development</code> mode) then the same behavior is expected to be working in the <code class="notranslate">production</code> mode (in the installer). Otherwise, if there is/are other work around to fix then still the expectation is same as to the <code class="notranslate">development</code> mode at the moment.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  ^5.37.0<br>
Node.js version: 14.16.0<br>
Operating System: macOS 10.14.6<br>
Additional tools: ffi-napi ver. ^4.0.3, ref-napi ver. ^3.0.2, webpack-cli ver. ^4.7.0, electron ver. ^12.0.7</p>
<p dir="auto">Simple, the nodejs webpack api doesn't run the same way as the webpack command line.</p>
<p dir="auto">I'm trying to write custom loaders and plugins, I'm stuck at the loaders and after banging my head, i see that it doesn't even work the same way as the command line one does. Why is this? How can i make the webpack node API behavior is the same way as the webpack command line?</p>
<p dir="auto">I want to get the file content from the loader and it doesn't pass that when call via node API, it pass a object</p>
<p dir="auto"><code class="notranslate">{resouce:'/path/to/file.js',...//other stuff}</code></p>
<p dir="auto">instead of a file i get the above. How do i get the file while running webpack with the nodejs API?</p>