-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require is not defined with es6 native modules => wrong import path and require fonction in webpack output #294
Comments
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? |
@pmmmwh I would happily. I'm having same issue. |
thanks @pmmmwh ! I can't test easily right now, since I reverted most of my changes related to migrating to esnext. (Too many things broken across various utilities I use) Thanks anyway for the quick feedback. thanks @SamMorrowDrums for stepping in ! |
I'm also seeing this issue, with a relatively minimal webpack config. Everything should be up to date, since I set up this project only a few days ago. Let me know if there's anything I can do to help. webpack.config.jsconst path = require("path");
const HtmlWebPackPlugin = require('html-webpack-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
const createConfig = isDevelopment => ({
entry: path.resolve(__dirname, 'src/index.js'),
//target: isDevelopment ? 'web' : 'browserslist',
output: {
path: path.resolve(__dirname, "dist"),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [
isDevelopment && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
})
module.exports = (env, argv) => createConfig(argv.mode === 'development') Also .babelrc, just in case{
"presets": [
[
"@babel/preset-env",
{
"bugfixes": true,
"useBuiltIns": "usage",
"corejs": "3.8",
"shippedProposals": true
}
],
"@babel/preset-react"
]
}
|
Hi, I'm implementing a fix for this issue. Just so I can understand the issue more, are you all running native ESM with Webpack 5+? My impression is that the fix might not work quite well in Webpack 4 if you run strict ESM (where |
Thanks. I'm using the latest version of Webpack 5 yes. |
Any updates with this fix? |
A fix should be ready this week. I'm planning to ship 0.5.0 within February. |
Great! Thank you 👍 |
Hi @pmmmwh, I have tried 5.0.0-beta.1 but |
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:
|
I'll try to release this today. The error semantics are the following with this change:
|
I there any update on this, anything people can help with? |
I'll try to push out the WIP new runtime on this tonight. |
I'm experiencing this problem in the latest rc with a package that uses the new package.json 'exports' member to define es6 modules. reactive/data-client#996 |
Rename the function. |
This has something to do with monorepo compatibility, it will be addressed in the next RC. |
Thanks @pmmmwh that's good to hear! <3 |
I'm having the same problem. After some debuging I found that the problem first occurs in the file
Obviously, I hacked this file this way:
Then, fortunately, the error 'required is not defined' was gone in this file but, unfortunately, it occurred in the file It was clearly begging me for another hacking, what I did in this way:
Again, the error was gone in that file but, to my despair, the error moved to another place related to a I guess that this has to be with a comment made by @pmmmwh above:
At the end, I'm under the impression that the (Webpack) code is a little "spaghettified" in that module - which represents a good opportunity for improvements - and that wouldn't be very easy to fix the problem. Does it make sense? Please, let me know. |
This sounds like either a bug on Webpack's side (what version are you using?) or a misconfiguration with your ESM setup. These files are internals of Webpack HMR and should not have to be touched for things to work. |
Did you find the required configurations of webpack or ESM setup to make this work? |
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:🔍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:
misc packages versions:
...
...
Thanks
The text was updated successfully, but these errors were encountered: