Skip to content
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

Does not work with React.lazy #42

Open
magic-m-johnson opened this issue Oct 14, 2020 · 2 comments
Open

Does not work with React.lazy #42

magic-m-johnson opened this issue Oct 14, 2020 · 2 comments

Comments

@magic-m-johnson
Copy link

magic-m-johnson commented Oct 14, 2020

deps

    "@babel/core": "^7.11.6",
    "@babel/preset-env": "^7.11.5",
    "@babel/preset-react": "^7.10.4",
    "babel-loader": "^8.1.0",
    "core-js": "^3.6.5",
    "html-webpack-plugin": "^4.5.0",
    "react": "^16.13.1",
    "react-dom": "npm:@hot-loader/react-dom",
    "regenerator-runtime": "^0.13.7",
    "webpack": "^5.1.0",
    "webpack-cli": "^4.0.0",
    "webpack-dev-server": "^3.11.0"

babel.config

{
  "presets": ["@babel/preset-env", "@babel/preset-react"]
}

webpack.config

const html = require('html-webpack-plugin')

module.exports = {
  mode: 'development',
  devtool: 'eval-source-map',
  plugins: [new html()],
  module: {
    rules: [{
      loader: "babel-loader",
      exclude: /node_modules/,
      test: /\.jsx?$/
    }]
  }
}

index.js

import 'core-js/stable'
import 'regenerator-runtime/runtime'
import React, { lazy, Suspense } from 'react'
import { render } from 'react-dom'

const Lazy = lazy(() => import('./lazy'))

render(<Suspense fallback={null}><Lazy /></Suspense>, document.body)

error:
image

@theKashey
Copy link
Contributor

npm:@hot-loader/react-dom is actually react-dom@17. Please use an explicit version matching your major React one.

@magic-m-johnson
Copy link
Author

thanks that helped.

I also added

    {
        test: /\.jsx?$/,
        include: /node_modules/,
        use: 'react-hot-loader/webpack',
      }

to my webpack config since i got the react-dom patch not detected warning, but now when I change something in a node_module it says "nothing changed".
I even added the modules i want to watch for changes to the webpack config watchOptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants