You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ node -r esm test.js
something
Warning: This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning.
error
The warning is caused by an exception happened in this try/catch block:
This is happening because esm module brings its own implementation of the module object with slightly different behavior which requires this context to be properly preserved.
React relied on undocumented behavior of Node modules loader. It was never guaranteed that it will work without proper this context.
In fact, it will not work as expected if you try it with any non built-in module
constnodeRequire=module.require;nodeRequire('timers');// built-in module, worksrequire('react')// proper require, also worksnodeRequire('react');// Error: Cannot find module 'react', even though the module is installed
The current code in React may break in future if timers module will be replaced with anything else, or if Node.js changes their internal implementation.
The text was updated successfully, but these errors were encountered:
React version: 16.13.1
Steps To Reproduce
This code works fine when using plain Node.js, but fails: when esm module is enabled:
The warning is caused by an exception happened in this
try/catch
block:react/packages/shared/enqueueTask.js
Lines 15 to 23 in 72d00ab
This is happening because
esm
module brings its own implementation of themodule
object with slightly different behavior which requiresthis
context to be properly preserved.This one-line change should do the fix:
This issue has also been reported to React-testing-library, which has similar code: testing-library/react-testing-library#614
Why should this be a fix in React and not in ESM?
React relied on undocumented behavior of Node modules loader. It was never guaranteed that it will work without proper
this
context.In fact, it will not work as expected if you try it with any non built-in module
The current code in React may break in future if
timers
module will be replaced with anything else, or if Node.js changes their internal implementation.The text was updated successfully, but these errors were encountered: