Next.js Discord

Discord Forum

DEPTH_ZERO_SELF_SIGNED_CERT in v13

Answered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hi, I'm new to Next JS and don't have a lot experience with Node generally. I'm trying to create a very basic POC to pull data from the locally hosted headless CMS.
When I try and pull data from the end point, I get the following error:
'FetchError: request to [localhost URL endpoint] failed, reason: self-signed certificate'
I keep coming across 'NODE_TLS_REJECT_UNAUTHORIZED' but I'm sure where (which file exactly) I need to put this to make it work.

I tried the:
...
"scripts": {
"dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 next dev",
...
},
...

in package.json as suggested by: https://code-specialist.com/cloud/nextjs-self-signed

I'm running 'npm run build ' when I get this error.

Can anyone help?
Answered by riský
ahh you can't run it like that in windows
View full answer

9 Replies

have you added the NODE_TLS_REJECT_UNAUTHORIZED=0 to the next build script also (and possibly start script too)?
Spectacled bearOP
'{
"name": "bla.head",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 next dev",
"build": "NODE_TLS_REJECT_UNAUTHORIZED=0 next build",
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 next start",
"lint": "next lint"
},
"dependencies": {
"next": "13.4.19",
"node-fetch": "^3.3.2",
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
'

When I run the following I still get an error:
'npm run build

bla.head@0.1.0 build
NODE_TLS_REJECT_UNAUTHORIZED=0 next build

'NODE_TLS_REJECT_UNAUTHORIZED' is not recognized as an internal or external command,
operable program or batch file.'
ahh you can't run it like that in windows
Answer
i think if you use powershell, you can do something similar to generate those env vars in your code: https://www.tutorialspoint.com/how-to-set-environment-variables-using-powershell
Spectacled bearOP
thanks, will take a look
Spectacled bearOP
ok so that sorted my problem. I ran this in the PowerShell terminal where I run my npm commands:
'[System.Environment]::SetEnvironmentVariable('NODE_TLS_REJECT_UNAUTHORIZED','0')'
and did it work?
Spectacled bearOP
yes, it started working, thanks for your help
yay!