티스토리 뷰


Node.js에서 모듈 설치 시에 다음과 같은 "self signed certificate in certificate chain" 에러를 만나게 되었을 때 아래 명령어로 해결 가능하다. 

 

$ set NODE_TLS_REJECT_UNAUTHORIZED=0

 

$ set npm_config_strict_ssl=false

 

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> geckodriver@3.0.1 postinstall D:\workspace\tistory2markdown\node_modules\geckodriver
> node index.js

Downloading geckodriver... events.js:292
      throw er; // Unhandled 'error' event
      ^

RequestError: self signed certificate in certificate chain
    at ClientRequest.<anonymous> (D:\workspace\tistory2markdown\node_modules\got\dist\source\core\index.js:956:111)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (D:\workspace\tistory2markdown\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
    at TLSSocket.onConnectSecure (_tls_wrap.js:1497:34)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket._finishInit (_tls_wrap.js:932:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12)
Emitted 'error' event on Request instance at:
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'SELF_SIGNED_CERT_IN_CHAIN',
  timings: {
    start: 1650937576520,
    socket: 1650937576523,
    lookup: 1650937576555,
    connect: 1650937576559,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1650937576598,
    abort: undefined,
    phases: {
      wait: 3,
      dns: 32,
      tcp: 4,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 78
    }
  }
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! geckodriver@3.0.1 postinstall: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the geckodriver@3.0.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

 

 

2. UnhandledPromiseRejectionWarning: Error: self signed certificate in certificate chain

 

 

C:\Program Files\nodejs\node.exe .\..\tistory2markdown\src\test\test_tistory_post.js
(node:5780) UnhandledPromiseRejectionWarning: Error: self signed certificate in certificate chain
    at TLSSocket.onConnectSecure (_tls_wrap.js:1497:34)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket._finishInit (_tls_wrap.js:932:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12)
    at TLSWrap.callbackTrampoline (internal/async_hooks.js:131:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5780) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:5780) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

 

vscode에서 실행, 디버깅 실행을 하는 경우 터미널 환경과 다르기 때문에 launch.json 에 환경 변수를 추가했다. 

 


            "env": {
                "NODE_TLS_REJECT_UNAUTHORIZED": "0"
            } // 추가

{
    // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
    // 기존 특성에 대한 설명을 보려면 가리킵니다.
    // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${file}",
            "env": {
                "NODE_TLS_REJECT_UNAUTHORIZED": "0"
            }
        },
        {
            "type": "node",
            "name": "Debug (Launch) - Current File",
            "request": "launch",
            "program": "${file}",
            "env": {
                "NODE_TLS_REJECT_UNAUTHORIZED": "0"
            }
            
        }
    ]
}

타 블로그 글 참고해보니 회사 내부 분리망을 사용하는 쪽에서 발생하는 것 같다. 나도 동일하고... 


댓글
최근에 올라온 글
최근에 달린 댓글