question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: React UMD cannot run in strict mode

See original GitHub issue

React version: 16.2.0

Steps To Reproduce

Run the code in your console:

import(‘https://cdn.jsdelivr.net/npm/react@16.12.0/umd/react.development.js’)

The current behavior

Uncaught (in promise) TypeError: Cannot set property 'React' of undefined

The expected behavior

React get loaded in the browser as globalThis.React.

Suggestion

Head of https://cdn.jsdelivr.net/npm/react@16.12.0/umd/react.development.js

'use strict';

(function (global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
	typeof define === 'function' && define.amd ? define(factory) :
	(global.React = factory());
}(this, (function () { 'use strict';

The this in the last line will always be undefined in strict mode. Consider use this || globalThis

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Jul 22, 2020

Yeah we’d be happy to bump Rollup if there’s a fix.

0reactions
Jack-Workscommented, Jul 22, 2020

It’s working in React 16.13.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does strict mode work differently with React 18?
When components are wrapped in StrictMode , React runs certain functions twice in order to help developers catch mistakes in their code.
Read more >
Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production build. You can enable strict mode for any...
Read more >
rollup.js
When in watch mode, run a shell command <cmd> for a watch event code. ... Imported values cannot be reassigned, though imported objects...
Read more >
Modules, introduction - The Modern JavaScript Tutorial
Always “use strict”. Modules always work in strict mode. E.g. assigning to an undeclared variable will give an error.
Read more >
TypeScript errors and how to fix them
error TS1117 : An object literal cannot have multiple properties with the same name in strict mode. Broken Code ❌. 1 2 3...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found