Error when compiling REACT

Asked

Viewed 671 times

1

I am getting the following error on my terminal when trying to compile React

./src/pages/main/index.js Line 3: 'api' is defined but never used no-unused-var

Follows the code:

import axios from 'axios'; 
const api = axios.create({ 
    baseURL: 'https://jsonplaceholder.typicode.com/posts'
}); 
export default api;
  • Is error or Warning?

  • Compiled with warnings. . /src/pages/main/index.js Line 3: 'api' is defined but Never used no-unused-vars Search for the Keywords to Learn more about each Warning. To ignore, add // Eslint-disable-next-line to the line before.

  • A Warning, I’m sorry.

  • The problem is that it does not boot the server.

  • But it gives build failed?

  • I see no problem in your code, as you are using in import? For your metro bundler, check your code and start all over again.

  • That’s a Warning, not a mistake.

  • Where are you calling the variable api ? Warning says it is set but is never called.

Show 3 more comments

1 answer

1

I see that you have created an API component and possibly imported it into the Main file (this is what should be done). But you are not calling the API import on your Main. Something like that:

main.js
...
import api from '../caminho/api' 
...

However you should not have called her anywhere on Main. Ai does not request and Main import is giving Warning.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.