Skip to content

Question: How does one use __non_webpack_require__? #1021

Closed

Description

@adjavaherian

Trying to figure out how to use this. Do I need to require('webpack') in my commonjs module?

I basically want Webpack to ignore a module that I'm requiring.

Activity

  1. sokra commented on Apr 29, 2015

    @sokra
    Member

    __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. FallingSnow commented on Nov 20, 2017

    @FallingSnow

    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. LeslieOA commented on Aug 11, 2020

    @LeslieOA

    __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)

  4. tungnat97 commented on Aug 11, 2021

    @tungnat97

    I got this error when using __non_webpack_require__: Cannot find name '__non_webpack_require__'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions