parcel: Parcel 2: React HMR error when changes occur

🐛 bug report

🎛 Configuration (.babelrc, package.json, cli command)

Command: parcel src/index.html

package.json:

{  
  ...
  "react-hot-loader": "^4.12.20",
  "react-dom": "npm:@hot-loader/react-dom@^16.13.0",
  "parcel": "^2.0.0-alpha.3.2",
  "app": "dist/index.html",
  "source": true,
  "targets": {
    "app": {
      "publicUrl": "./"
    }
  }
}

.babelrc:

{
    "presets": ["@babel/preset-typescript", "@babel/preset-react", "@babel/preset-env"],
    "plugins": [
      [
        "@babel/plugin-proposal-class-properties",
        {
          "loose": true
        }
      ]
    ]
  }

🤔 Expected Behavior

HMR works

😯 Current Behavior

When I make a change and save the file, this error is thrown:

version-3.e9b82067.js:84 Uncaught TypeError: Cannot read property '../../../../node_modules/@parcel/transformer-react-refresh-wrap/lib/helpers/helpers.js' of undefined
    at Function.resolve (version-3.e9b82067.js:84)
    at localRequire (version-3.e9b82067.js:80)
    at Object.eval (eval at hmrApply (HMRRuntime.js:170), <anonymous>:5:15)
    at newRequire (version-3.e9b82067.js:68)
    at hmrAcceptRun (HMRRuntime.js:232)
    at WebSocket.ws.onmessage (HMRRuntime.js:69)

💁 Possible Solution

No idea.

🔦 Context

I am trying to enable react-hot-loader in a React + TypeScript project.

💻 Code Sample

import { hot } from 'react-hot-loader';
const App = () => <div>Hello!</div>;
export default hot(module)(App);

// I also tried adding this
if ((module as any).hot) {
    (module as any).hot.accept();
}

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-alpha.3.2
Node 10.16
npm/Yarn npm 6.9
Operating System Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 19 (4 by maintainers)

Most upvoted comments

I think a lot of issues (including this one) are solved in the nightly builds parcel@nightly. The alpha version is pretty old.

Can you please provide a minimal reproduction?

I have a pretty big project, so I will have to create a new project from scratch and hope it brakes, will take some time. I will try to do it tomorrow.