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
Starting from version 5.71.0, when evaluating the operation const hasPortalSupport = 'createPortal' in ReactDOM. It generates a bundle with const hasPortalSupport = false. Probably connected with PR #15455.
The expected behavior is that the build time eval equals the runtime eval. The expression const hasPortalSupport = 'createPortal' in ReactDOM; should be evalued as const hasPortalSupport = true;
Other relevant information:
webpack version: 5.72.0 (the bug starts to happen in version 5.71.0)
Node.js version: v16.14.2
Operating System: Ubuntu 20.04.4 LTS
The text was updated successfully, but these errors were encountered:
@vankop I see, I will update the code accordingly, pardon my ignorance, I have a hard time understanding the way modules are exported/imported, but just to see if I understood more or less of what is happening:
with import ReactDOM from 'react-dom' in build time, webpack tries to import the default export from react-dom which doesn't exist, therefore it is evaluated as false, but it exists in runtime because of something webpack (or depending on the tools babel, or tsconfig) does to normalize the way the imports are made.
by importing with import * as ReactDOM from 'react-dom' we are importing everything that is exported (and not just the default) with the name of ReactDOM which can then be evaluated correctly.
one last question: in build time can't know we that the syntax import ReactDOM from 'react-dom' would be "wrong", so that we are able to bail out from the evaluation and keep the original value?
Bug report
What is the current behavior?
Starting from version
5.71.0
, when evaluating the operationconst hasPortalSupport = 'createPortal' in ReactDOM
. It generates a bundle withconst hasPortalSupport = false
. Probably connected with PR #15455.I've created a stackblitz repo, with the relevant files
index.js
webpack.config.js
package.json
What is the expected behavior?
The expected behavior is that the build time eval equals the runtime eval. The expression
const hasPortalSupport = 'createPortal' in ReactDOM;
should be evalued asconst hasPortalSupport = true;
Other relevant information:
webpack version:
5.72.0
(the bug starts to happen in version5.71.0
)Node.js version:
v16.14.2
Operating System:
Ubuntu 20.04.4 LTS
The text was updated successfully, but these errors were encountered: