0

When I run npm run build I get the error of the following screenshot, I have tried to investigate it and reading other topics I see that performing npm cache clean can solve the problem, but in my case this gives again other errors. So I don't know what I can try to fix it. I would appreciate some help, thank you very much.

enter image description here

Edit with the field [url].js

since the error seems to come from this file I share it with you to see what it could be

import Layout from "../../components/Layout"
import Image from "next/image"
import { formatearFecha } from "../../helpers"
import styles from '../../styles/Entrada.module.css'

const EntradaBlog = ({entrada}) => {

  const {contenido, imagen, titulo, published_at} = entrada

  return (
    <Layout pagina={titulo}>
        <main className="contenedor">
            <h1 className="heading">{titulo}</h1>
            <article className={styles.entrada}>
                <Image src={imagen.url} alt={`img entrada - ${titulo}`} width={300} height={200} layout='responsive' />
                <div className={styles.contenido}>
                    <small>Publicado el: <span className={styles.fecha_span}>{formatearFecha(published_at)}</span></small>
                    <p className={styles.texto_contenido}>{contenido}</p>
                </div>
            </article>
        </main>
    </Layout>
  )
}


export async function getStaticPaths(){ 
    const url = `${process.env.NEXT_PUBLIC_API_URL}/blogs`
    const respuesta = await fetch(url)
    const entradas = await respuesta.json()
    const paths = entradas.map(entrada => ({
        params: { url: entrada.url }
       
    }))
    return {
        paths: paths,
        fallback: false 
    }
}
export async function getStaticProps({params: { url }}){ //se encarga de traer la información que irá en cada página
    const urlBlog = `${process.env.NEXT_PUBLIC_API_URL}/blogs?url=${url}`
    const respuesta= await fetch(urlBlog)
    const entrada = await respuesta.json()
    return {
        props: {
            entrada: entrada[0],
        }
    }
}

export default EntradaBlog
Juan Jesús
  • 105
  • 8
  • Do you have anything running on `localhost:1337` (supposedly, your `process.env.NEXT_PUBLIC_API_URL` value)? Your Next.js app is trying to make a request against `http://localhost:1337/blogs` but it's failing with `ECONNREFUSED`. Were you expecting something to get returned back from that address? – juliomalves Aug 30 '22 at 21:32
  • Hi there, sorry for not answering sooner, I went on vacation and disconnected. The variable process.env.NEXT_PUBLIC_API_URL has as value a url, a project of mine with strapi deployed in heroku that is in production, that generates me the backend, the APIs of my application in next.js. The url to which I am trying to make the request works perfectly. However I have another file called .env.local which has the same variable name, and points to http://localhost:1337, maybe it is taking that variable instead of the one in the .env file ? I doubt it. Best Regards – Juan Jesús Sep 03 '22 at 21:45

0 Answers0