typescript 运行简单的开发命令后出现pg错误

esbemjvw  于 2022-11-30  发布在  TypeScript
关注(0)|答案(2)|浏览(231)

我有一个非常简单的typeorm,pg设置和脚本只是纱开发。我得到这个错误不知何故。

AssertionError [ERR_ASSERTION]: unknown message code: 4a
    at Parser.handlePacket (/Users/dmitriyshin.io/Desktop/Web/React/1. Courses Projects/Uber Clone with TypeScript, Apollo, GraphQL and NodeJS/nuber-server/node_modules/pg-protocol/src/parser.ts:198:16)
    at Parser.parse (/Users/dmitriyshin.io/Desktop/Web/React/1. Courses Projects/Uber Clone with TypeScript, Apollo, GraphQL and NodeJS/nuber-server/node_modules/pg-protocol/src/parser.ts:101:30)
    at Socket.<anonymous> (/Users/dmitriyshin.io/Desktop/Web/React/1. Courses Projects/Uber Clone with TypeScript, Apollo, GraphQL and NodeJS/nuber-server/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
[nodemon] app crashed - waiting for file changes before starting...
z31licg0

z31licg01#

此问题是由postgres连接问题引起地(连接器报告一条不适当地消息);
解决方案:检查postgres安装以及它是否正在运行

n7taea2i

n7taea2i2#

这个问题也发生在你试图连接postrgres与mysql连接字符串。更多详情here
一个临时的解决方案是全局处理uncaughtException

process.on('uncaughtException', e => {
    console.error('An unhandled exception occurred:');
    
    if(  e.message == 'unknown message code: 4a' && e.code  == 'ERR_ASSERTION'){
      console.error( "Postgres error"); 
      // do what you want to do here  
    }
    else{  
    console.error(e);   
    process.exit (1);
      
    }
  
  });

相关问题