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.

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)

See original GitHub issue

Current Behavior

I suddenly started to receive the error below in some of my components.

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)

image

Expected behavior

No errors are displayed.

Suggested solution(s)

A temporary workaround is adding “import React from ‘react’” on the top of the file. Changing the VSCode typescript version does not work. Adding jsx: “react-dev” to tsconfig.json breaks tsdx build process.

Your environment

  System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 7.26 GB / 15.51 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 93.0
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1 
    typescript: ^4.6.2 => 4.7.4 

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
jonit-devcommented, Sep 8, 2022

Facing the same issue

I solved it by importing React manually in all story files.

Unfortunately… 😞

0reactions
priyang12commented, Oct 7, 2022

You can set the ts version of tsdx to 4.4 or afterwards. hopefully new version will upgrade the ts. for now manually works.

if you are using yarn than you can

"resolutions": {
    "tsdx/typescript": "^4.7.4",
}

or npm

"overrides": {
 "tsdx/typescript": "^4.7.4",
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

'React' refers to a UMD global, but the current file is a module
'React' refers to a UMD global, but the current file is a module · "I know with this new version you don't have...
Read more >
React refers to UMD global, but the current file is a module
To solve the error "'React' refers to a UMD global, but the current file is a module. Consider adding an import instead", update...
Read more >
React' refers to a UMD global, but the current file is a module ...
This error message comes from TypeScript compiler. The React 17 new jsx transform is not currently supported in Typescript 4.0, and will be...
Read more >
angular/angular-cli - Gitter
Error:(54, 33) TS2686:'fabric' refers to a UMD global, but the current file is a module. Consider adding an import instead.
Read more >
Documentation - Global: Plugin - TypeScript
The same footnote applies to these modules. If your module is not callable or constructable, use the module.d.ts file. Module Plugin or UMD...
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