Skip to content

ProvidePlugin injection into .mjs files seems to be broken #7032

@xandris

Description

@xandris

Do you want to request a feature or report a bug?

A bug, I think.

What is the current behavior?

At runtime, a .mjs module with injections from ProvidePlugin will throw an error at runtime, indicating that require is not defined. The final module code produced by webpack looks like this:

/*! no static exports found */
/***/ (function(module, exports) {

/* WEBPACK VAR INJECTION */(function(foo) {console.log(foo);
/* WEBPACK VAR INJECTION */}.call(this, require("/Users/aparker/src/notes/webpack4upgrade/mjs-provide/foo.js")))

/***/ })

/******/ });

(Note the call to require.)

If the current behavior is a bug, please provide the steps to reproduce.

You can reproduce the behavior using this repository.

What is the expected behavior?

The module should look more like this:

/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(foo) {console.log(foo);
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./foo.js */ "./foo.js")))

/***/ })

/******/ });

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

  • node -v: v9.11.1
  • webpack -v: 4.5.0
  • OS: Mac OS 10.13.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions