react-refresh-webpack-plugin: require is not defined with es6 native modules => wrong import path and require fonction in webpack output
I get a
π΄ ReferenceError
require is not defined
πI use esm native modules. πMy config matches the readme
but webpack generate a weird import line for __webpack_require__.$Refresh$.runtime
for every module:
WRONG REQUIRE v WRONG PATH v
__webpack_require__.$Refresh$.runtime = require('C:/Users/myusername/dev/devops-cli/node_modules/react-refresh/runtime.js');
πit is as if it was not using the correct require, nor rewriting properly the path.
You can find more details below as well as a longer extract from webpack output. What else can I provide ?
Any help or workaround appreciated ! π
config:
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
]
....
module: {
rules: [
{
// https://github.com/pmmmwh/react-refresh-webpack-plugin
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: { plugins: [require.resolve('react-refresh/babel')], },
},
],
},
]
}
misc packages versions:
- β@pmmmwh/react-refresh-webpack-pluginβ: β0.4.3β, β¦
- β@babel/coreβ: β7.12.10β,
- β@babel/plugin-proposal-decoratorsβ: β^7.12.12β,
- β@babel/plugin-transform-react-jsxβ: β^7.12.12β,
- β@babel/preset-reactβ: β^7.12.10β,
- β@babel/preset-typescriptβ: β^7.12.7β, β¦
/***/ "./packages/test/counterUI1.js":
/*!*************************************!*\
!*** ./packages/test/counterUI1.js ***!
\*************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "CounterUI": () => /* binding */ CounterUI,
/* harmony export */ "foo": () => /* binding */ foo
/* harmony export */ });
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "./node_modules/react/index.js");
/* harmony import */ var _emotion_react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @emotion/react */ "./node_modules/@emotion/react/dist/emotion-react.browser.esm.js");
/* provided dependency */ var __react_refresh_utils__ = __webpack_require__(/*! ./node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils.js */ "./node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils.js");
/* provided dependency */ var __react_refresh_error_overlay__ = __webpack_require__(/*! ./node_modules/@pmmmwh/react-refresh-webpack-plugin/overlay/index.js */ "./node_modules/@pmmmwh/react-refresh-webpack-plugin/overlay/index.js");
v HERE v
__webpack_require__.$Refresh$.runtime = require('C:/Users/rvion/dev/devops-cli/node_modules/react-refresh/runtime.js');
__webpack_require__.$Refresh$.setup(module.id);
Thanks
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 23 (8 by maintainers)
Iβll try to push out the WIP new runtime on this tonight.
Thanks. Iβm using the latest version of Webpack 5 yes.
This has something to do with monorepo compatibility, it will be addressed in the next RC.
Hi, unfortunately the semantics needed for the fix is a bit more complex than expected.
The runtime is currently in a half-baked state where some tests pass and some donβt (hopefully some progress in a PR soon). Iβm continuously working on it currently.
In particular, some blockers:
var
,const
,let
)A fix should be ready this week. Iβm planning to ship 0.5.0 within February.
Hi, thanks for reporting this bug. I think this has something to do with our way of injecting dependencies via a loader. I can publish a beta version that might fix this, would you mind trying it out to see if it works or provide a minimal native ESM webpack project for reproduction?