Skip to content

Hot Module Replacement fails if CxJS packages are used (started recently) #985

Closed
@mstijak

Description

@mstijak

🐛 bug report

Description of the problem

I noticed that HMR doesn't work for CxJS based templates. The update fails with error
Cannot set property computable of #<Object> which has only a getter.
I reproduced the issue with vanilla template too and you can see it in the attached sandbox.
This issue is easily reproducible with CxJS, but the problem might not be CxJS specific.
On every change, for unknown reason, the module node_modules/cx/dist/ui.js gets re-evaluated. On second run, the exports object passed to the evaluate function is non-empty and the function fails. You can easily see that if you add a breakpoint in that module.

The file re-exports the computable function from another module like this:

export { computable } from "cx/data";

This gets translated into

exports.computable = undefined;

var _data2 = require("./data");

Object.defineProperty(exports, "computable", {
	enumerable: true,
	get: function () {
		return _data2.computable;
	}
});

On second run, it fails on the first line.

I tried to replicate the issue without using the cx package, but, for local files, exports is an empty object on each run. I guess that files in node_modules and src files are treated differently for some reason. I'm not sure how to fix this on my own and I really hate that yarn install fails on Windows. Any help would be highly appreciated.

How has this issue affected you? What are you trying to accomplish?

HMR shuld work for CxJS based sandboxes.

Link to sandbox: 94qq4l97ly

Your Environment

Software Name/Version
Сodesandbox Lastest
Browser Chrome
Operating System Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions