3 thoughts on “Question: How does one use __non_webpack_require__?

  1. __non_webpack_require__ is the original require function which exists in the environment before webpack comes in.


    Ignoring modules is a separate thing.

    You can do that with the browser field, the IgnorePlugin or resolve.alias.

  2. 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.

  3. __non_webpack_require__ is the original require function which exists in the environment before webpack comes in.

    Ignoring modules is a separate thing.

    You can do that with the browser field, the IgnorePlugin or resolve.alias.

     

    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)

Comments are closed.