Skip to content

'React' refers to a UMD global, but the current file is a module. #14118

@Jameskmonger

Description

@Jameskmonger

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

// a.tsx
import React from "react";

export class SomeComponent extends React.Component<{}, {}> {
  public render() {
    return <div><span>Hi!</span></div>;
  }
}
 
// b.tsx
import { SomeComponent } from "./a";

let x = <SomeComponent />; // error line

Expected behavior:
No errors - React refers to the React imported in a.tsx, not a global.

Actual behavior:

error TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead

Error is on the line marked // error line above.

The error can be subdued by adding any of the following in b.tsx.

declare var React: any;
var React;
import React from "react";
import * as React from "react";

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions