Home > Software design >  I am not able to run program coz of this error
I am not able to run program coz of this error

Time:09-23

I am designing Netflix clone and is working fine but when I uncomment Banner component in my App.js file , its showing error error: ./src/axios.js 10:12 Module parse failed: Cannot use keyword 'await' outside an async function (10:12) File was processed with these loaders:

  • ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
  • ./node_modules/babel-loader/lib/index.js You may need an additional loader to handle the result of these loaders. | baseURL: "https://api.themoviedb.org/3/movie/550?api_key=b0d1867018a029a8bfcc00a0d74c1e2f" | });
 const res = await axios.get('https://api.themoviedb.org/3/trending/all/week?api_key=b0d1867018a029a8bfcc00a0d74c1e2f&language=en-US');
 console.log(res);
 instance. Get('/foo-bar')

CodePudding user response:

It is mandatory to use await inside of an async function only.

const fName = async() => {
     const res = await axios.get('https://api.themoviedb.org/3/trending/all/week? 
     api_key=b0d1867018a029a8bfcc00a0d74c1e2f&language=en-US');
     console.log(res);
     instance. Get('/foo-bar')
}

CodePudding user response:

You have to use await always inside the asynchronous function below is the syntax.

    const functionName = async () => {
        await axios(************)
    }

    async function functionName(){
        await axios(*********)
    }
  • Related