require is not defined with es6 native modules => wrong import path and require fonction in webpack output
See original GitHub issueI 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:23 (8 by maintainers)
Top Results From Across the Web
webpack : Uncaught ReferenceError: require is not defined
My issue was in my package.json, I had to remove. "type":"module".
Read more >How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >Module Methods - webpack
If dependencies are not provided, factoryMethod is called with require , exports and module (for compatibility!). If this function returns a value, this...
Read more >How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >A Guide to Managing Webpack Dependencies - Toptal
The Webpack module bundler processes JavaScript code and all static assets, ... For this purpose, we can use require.ensure or System.import functions,Β ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Iβll try to push out the WIP new runtime on this tonight.
Thanks. Iβm using the latest version of Webpack 5 yes.