node:internal/errors:464 ErrorCaptureStackTrace(err);

31.4k views Asked by At

When I was trying to add secure API keys in the .env file, I got this error:

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-RapidAPI-Host"
    at ClientRequest.setHeader (node:_http_outgoing:579:3)
    at new ClientRequest (node:_http_client:256:14)
    at Object.request (node:https:353:10)

Below is my code:

const axios = require("axios");

const BASE_URL = `https://mashape-community-urban-dictionary.p.rapidapi.com`

module.exports = {
    getCompatibility: (yourSearch) => axios({
        method:"GET",
        url : BASE_URL + `/define`,
        headers: {
          'X-RapidAPI-Host': process.env.rapidapi_host,
          'X-RapidAPI-Key': process.env.Rrapidapi_key
        },
        params: {
            term: yourSearch
        }
    })
}

My env file:

rapidapi_host={my secure host}
rapidapi_key={my secure key}

Can anyone explain why that is happening?

4

There are 4 answers

0
Lais Gomes On

For me I solved this error just by putting the file extension in the import.

For example, instead of writing import { file } from "file", I wrote import { file } from "file.js" in all files.

0
Ayaan Kaifullah On

Intsconfig you are using NodeNext. So in that case we have the liberty to use both of te types. So while importing from any file you have to put the file extension. This is not the case while importing from any module. If you dont want to do that then replace the NodeNext with the exact version of your need.

0
Vladimir Georgiev On

This error means that the value of the X-RapidAPI-Host header you are passing is empty.

Check whether you are properly setting the rapidapi_host environment variable for the process.

0
Chandan On

Not sure of the reason but deleting the node_modules folder and reinstalling with npm i solved it for me.