Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Property does not exist on type 'never'.ts(2339) in axios response in NextJs

I am working on a NextJs project and I am very new to NextJs. I was facing a problem with Axios. I am using VS code and was trying to access (response.data.sliders) but my editor was showing an error. The error was "Property 'sliders' does not exist on type 'never'.ts(2339)". But after doing console.log(response.data), I can clearly see the 'sliders' there. I was getting sliders data but vs code was showing the error. I was quite frustrated about it but suddenly when I was thinking to ask a question here regarding my problem, I got the solution and it worked magically for me! So I thought why not write the solution with the problem so that other people like me can get help from it. I will attach a screenshot and a little code snippet of my project so that you can understand my problem clearly. This is the result of console.log(response.data)

And here is my code.

import axios from "axios";
const IndexPage = (props) => {
  return (
    <main>
      <Section1 Section1Props={props.Section1Props} />
     
    </main>
  );
};


export async function getServerSideProps(context) {
  try {
    const response = await axios.get(urlGenerator("api/v1/frontend-configuration"));
    
    const data = await response.data;

    return {
      props: {
        Section1Props : data.sliders, // here I was getting the error for 'sliders'
        
      },
    }
    
  } catch (error) {
    console.log(error);
    
  }
  
}

export default IndexPage;

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I solved my problem by declaring the response variable as follows

const responseTest: AxiosResponse<any>  = await axios.get('https://api.github.com/users/maths032')
    
    
  alert(responseTest.data.id)

and importing axios as follows

import axios, { AxiosResponse } from "axios";

I don't know if it's the best way, but it works for me.

about 4 years ago · Juan Pablo Isaza Relatório

0

Finally I found out that the problem is in my axios import statement. I need to import axios like this -

const { default: axios } = require('axios'); // or
const axios = require('axios').default;

Instead of this -

import axios from "axios";

I don't know why it worked though. Still I am feeling happy and hope it helped you too. If you know why it worked, please explain it here. It will be helpful for me to understand the whole thing.

about 4 years ago · Juan Pablo Isaza Relatório

0

From the axios docs:

In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require() use the following approach:

const axios = require('axios').default;

// axios.<method> will now provide autocomplete and parameter typings

I needed an ESM import so below is how I did:

import axios, { AxiosResponse, AxiosError } from 'axios';
const Axios = axios.default;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda