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.

Type error: Cannot find global value 'Promise'. TS2468

See original GitHub issue

Is this a bug report?

YES (write your answer here) When I tried to use lazy api from 16.6 version of react with Typescript, I get this Error

I’m using react-scripts 2.1.1 with typescript

and this typing file for 16.6 & 16.7.0 api


import * as React from 'react';

declare module 'react' {
  // React 16.6

  function memo<Props>(component: React.StatelessComponent<Props>): React.StatelessComponent<Props>;

  function lazy<P, Component extends React.ComponentType<P>>(
    importFn: () => Promise<Component | {default: Component}>,
  ): Component;

  const Suspense: React.ComponentType<{fallback?: React.ReactNode}>;

  // React 16.7

  type StateUpdateFunction<State> = (newState: State | ((oldState: State) => State)) => void;

  function useState<State>(
    initialState: State | (() => State),
  ): [State, StateUpdateFunction<State>];

 function useEffect(
    f: () => void | Promise<void> | (() => void | Promise<void>),
    keys?: any[],
  ): void;
  function useMutationEffect(
    f: () => void | Promise<void> | (() => void | Promise<void>),
    keys?: any[],
  ): void;
  function useLayoutEffect(
    f: () => void | Promise<void> | (() => void | Promise<void>),
    keys?: any[],
  ): void;

  function useContext<Context>(context: React.Context<Context>): Context;

  type Reducer<State, Action> = (state: State, action: Action) => State;
  function useReducer<State, Action>(
    reducer: Reducer<State, Action>,
    initialState: State,
    initialAction?: Action,
  ): [State, (action: Action) => void];

  function useCallback<Callback extends Function, R>(f: Callback, keys?: any[]): Callback;
  function useMemo<Value>(f: () => Value, keys?: any[]): Value;

  function useRef<T>(): {current: T | null};
  function useRef<T>(initial: T): {current: T};

  function useImperativeMethods<Ref, ImperativeMethods>(
    ref: React.Ref<Ref> | undefined,
    f: () => ImperativeMethods,
    keys?: any[],
  ): void;
}

Type error: Cannot find global value 'Promise'. TS2468

there is my code:

import { Spin } from 'antd';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Menu from './components/Header';
import './App.css';

const Home = lazy(() => import('./components/Home'));
function App() {
  return (
    <>
      <Menu />
      <Router>
        <Suspense fallback={<Spin />}>
          <Route exact path="/home" component={Home} />
        </Suspense>  
      </Router>  
    </>
  );
}


export default App;```
<!--
  If you answered "Yes":
  
    Please note that your issue will be fixed much faster if you spend about
    half an hour preparing it, including the exact reproduction steps and a demo.
    
    If you're in a hurry or don't feel confident, it's fine to report bugs with
    less details, but this makes it less likely they'll get fixed soon.

    In either case, please fill as many fields below as you can.

  If you answered "No":

    If this is a question or a discussion, you may delete this template and write in a free form.
    Note that we don't provide help for webpack questions after ejecting.
    You can find webpack docs at https://webpack.js.org/.
-->

### Did you try recovering your dependencies?

Yes 

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
Timercommented, Nov 2, 2018

Please read the TypeScript handbook to learn more about this.

5reactions
pladariacommented, Nov 2, 2018

try adding "lib": ["es2018", "dom"], to tsconfig.json in compilerOptions section

tsconfig.json file:

{
    "compilerOptions": {
        ...
        "lib": ["es2018", "dom"],
        ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS2468: Cannot find global value 'Promise'
tsc command is probably not picking up the tsconfig.json file. I think it happens when you specify the source file in the command...
Read more >
TS2468 Cannot find global value 'Promise'--unit tests only
I have a Node project that uses typescript 2.5.2 (though this bug has been there since TS 2.1). In my unit tests I...
Read more >
TS2468: Cannot find global value 'Promise'. - Fitbit Community
Solved: I'm trying to write a simple app which downloads my upcoming events from Google Calendar and lists them as an agenda on...
Read more >
TypeScript errors and how to fix them
error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Promise ' has no compatible call signatures. Broken Code ❌....
Read more >
3xt9a39dr - TypeScript - OneCompiler
error TS2468 : Cannot find global value 'Promise'. script.ts(1,25): error TS2307: ... 'Promise' only refers to a type, but is being used as...
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