You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: How does one use __non_webpack_require__? #1021
I cannot believe how long it has taken me to find __non_webpack_require__. All I wanted to do was require at runtime and I ended up finding require.ensure, System.import, await import(). All of which didn't work for a fully dynamic require.
Is it possible to get more documentation for this keyword? Also why isn't there a require.dynamic() or require.runtime() function, is there a reason webpack doesn't do this?
P.S. My use case was to read a config.js file which has its filename provided at runtime via a command line flag.
Reacted by Bharat Patil, Yves M., Cobertos, novwhisky, Xanthus Wong, ericbiewener, David Walton, Mountain Ghost. W, Ersin Akinci, Omid Amraei and 24 more
Reacted by David Walton, Bouali Kamel, Yiin, Tyler Shin, Florian Schmidt, Sergey Starodubov, Leslie Owusu-Appiah, Ahmet Akkoç and duhmojo
Reacted by novwhisky, Bouali Kamel, Yiin, Michael Sogos, Tyler Shin, Florian Schmidt, Leslie Owusu-Appiah, Ahmet Akkoç and duhmojo
Activity
sokra commentedon Apr 29, 2015
__non_webpack_require__is the originalrequirefunction which exists in the environment before webpack comes in.Ignoring modules is a separate thing.
You can do that with the
browserfield, the IgnorePlugin or resolve.alias.FallingSnow commentedon Nov 20, 2017
I cannot believe how long it has taken me to find
__non_webpack_require__. All I wanted to do was require at runtime and I ended up findingrequire.ensure,System.import,await import(). All of which didn't work for a fully dynamic require.Is it possible to get more documentation for this keyword? Also why isn't there a
require.dynamic()orrequire.runtime()function, is there a reason webpack doesn't do this?P.S. My use case was to read a config.js file which has its filename provided at runtime via a command line flag.
LeslieOA commentedon Aug 11, 2020
Just incase the above isn't clear enough for anyone who stumbles upon this in the future,
you literally just have to replace:
const someModule = require('some-module)...with:
const someModule = __non_webpack_require__('some-module)tungnat97 commentedon Aug 11, 2021
I got this error when using __non_webpack_require__: Cannot find name '__non_webpack_require__'.