Type error: Cannot find global value 'Promise'. TS2468
See original GitHub issueIs 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:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please read the TypeScript handbook to learn more about this.
try adding
"lib": ["es2018", "dom"],
totsconfig.json
incompilerOptions
sectiontsconfig.json file: