admin管理员组

文章数量:1317560

I have some code that was working now it currently isn't even though the code hasn't changed. I am on a different puter now though.

I am getting an error about replacing a value with null though I have done some testing (console.log) and looks like nothing is ing back null. Below is the code as well as the error message. I did check the 'config' variable and it does have a value. I am wondering what this error means/what is causing it. I have tried google and found a few issues about it however none have a solution in them just a lot of "me too" responses.

Code

console.log(message)
axios.post(config.EXPRESS_URL, {
      content: message.content,
      abut_code: message.abut_code,
      media_url: '',
      userID: message.userID,
      name: message.name
}, {headers})
.then(() => {
      console.log('Message sent')
})
.catch(err => {
      console.log(err)
})

Error message/console output

{
  content: 'test',
  abut_code: 'bff1377f:d7de22eb',
  userID: 'auth0|613a9e709518390070831c29',
  name: 'Me 2'
}
TypeError: Cannot read property 'replace' of null
    at dispatchHttpRequest (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/adapters/http.js:109:74)
    at new Promise (<anonymous>)
    at httpAdapter (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/adapters/http.js:46:10)
    at dispatchRequest (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/core/dispatchRequest.js:52:10)

I have some code that was working now it currently isn't even though the code hasn't changed. I am on a different puter now though.

I am getting an error about replacing a value with null though I have done some testing (console.log) and looks like nothing is ing back null. Below is the code as well as the error message. I did check the 'config' variable and it does have a value. I am wondering what this error means/what is causing it. I have tried google and found a few issues about it however none have a solution in them just a lot of "me too" responses.

Code

console.log(message)
axios.post(config.EXPRESS_URL, {
      content: message.content,
      abut_code: message.abut_code,
      media_url: '',
      userID: message.userID,
      name: message.name
}, {headers})
.then(() => {
      console.log('Message sent')
})
.catch(err => {
      console.log(err)
})

Error message/console output

{
  content: 'test',
  abut_code: 'bff1377f:d7de22eb',
  userID: 'auth0|613a9e709518390070831c29',
  name: 'Me 2'
}
TypeError: Cannot read property 'replace' of null
    at dispatchHttpRequest (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/adapters/http.js:109:74)
    at new Promise (<anonymous>)
    at httpAdapter (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/adapters/http.js:46:10)
    at dispatchRequest (/Users/me/projects/tenanttalk/backend/websocket/node_modules/axios/lib/core/dispatchRequest.js:52:10)
Share Improve this question asked Sep 26, 2021 at 1:14 joshk132joshk132 1,1131 gold badge18 silver badges51 bronze badges 4
  • No, it means something tried to read somevalue.replace but somevalue was null. The error was because it ended up trying to read null.replace, which, of course, isn't valid. – Ouroborus Commented Sep 26, 2021 at 1:22
  • it looks like the error is in the backend side, I believe – Daniel Sifontes Commented Sep 26, 2021 at 2:09
  • @Ouroborus okay so what is null? That is the part that makes no sense, I can console.log all values and get an output. – joshk132 Commented Sep 26, 2021 at 2:25
  • @DanielSifontes Backside? Do you mean the API endpoint Axios is trying to reach? If so I don't think that is the case as I can use postman to test it and it works plus this Axios request never actually seems to hit the API server and is failing before it hits it – joshk132 Commented Sep 26, 2021 at 2:27
Add a ment  | 

1 Answer 1

Reset to default 7

I had the same error when the provided url was not correct (I forgot the "http://" in the url in my case) check config.EXPRESS_URL and make sure it's a valid url.

本文标签: javascriptTypeError Cannot read property 39replace39 of nullAxiosStack Overflow