首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的文档化LoopBack4应用程序无法成功运行,并收到消息"ConnectionError:查找实例失败“?

问为什么我的文档化LoopBack4应用程序无法成功运行,并收到消息"ConnectionError:查找实例失败“?
EN

Stack Overflow用户
提问于 2020-06-29 02:02:12
回答 1查看 230关注 0票数 0

我创建了一个LoopBack 4应用程序来实现LoopBack 4教程中用户数据模型上的CRUD操作,该应用程序在VSCode和Dockerization (Linux模式)中运行良好。之后,我添加了基于用户名和密码的基本身份验证功能。该应用程序在我的VSCode中再次运行良好,但由于"ConnectionError:未能查找实例“错误而失败地运行。

我的码头引擎: 19.03.8

我的操作系统: Windows 10 Pro

我的LB4应用程序:https://github.com/frank-nguyen-vd/LB4-Tutorial

来自码头的错误日志:

​

代码语言:javascript
复制
Mon, 29 Jun 2020 01:39:59 GMT tedious deprecated The default value for `config.options.enableArithAbort` will change from `false` to `true` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. at node_modules/mssql/lib/tedious/connection-pool.js:61:23
Server is running at http://127.0.0.1:3000

Try http://127.0.0.1:3000/ping

Connection fails: ConnectionError: Failed to lookup instance on HOPE-L-191 - getaddrinfo ENOTFOUND HOPE-L-191

It will be retried for the next request.

events.js:174

throw er; // Unhandled 'error' event

^


ConnectionError: Failed to lookup instance on HOPE-L-191 - getaddrinfo ENOTFOUND HOPE-L-191

at Connection.tedious.once.err (/home/node/app/node_modules/mssql/lib/tedious/connection-pool.js:68:17)

at Object.onceWrapper (events.js:286:20)

at Connection.emit (events.js:198:13)

at _instanceLookup.InstanceLookup.instanceLookup (/home/node/app/node_modules/tedious/lib/connection.js:1100:16)

at sender.execute (/home/node/app/node_modules/tedious/lib/instance-lookup.js:69:13)

at GetAddrInfoReqWrap.invokeLookupAll [as callback] (/home/node/app/node_modules/tedious/lib/sender.js:155:16)

at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:68:17)

Emitted 'error' event at:

at UserDsDataSource.postInit (/home/node/app/node_modules/loopback-datasource-juggler/lib/datasource.js:502:16)

at /home/node/app/node_modules/loopback-connector-mssql/lib/mssql.js:36:19

at Immediate.<anonymous> (/home/node/app/node_modules/loopback-connector-mssql/lib/mssql.js:89:14)

at runCallback (timers.js:706:11)

at tryOnImmediate (timers.js:676:5)

at processImmediate (timers.js:658:5)

​

我的Dockerfile:

代码语言:javascript
复制
FROM node:10-slim
USER node
RUN mkdir -p /home/node/app
WORKDIR /home/node/app
COPY --chown=node package*.json ./
COPY --chown=node . .
RUN npm run build
ENV HOST=0.0.0.0 PORT=3000
EXPOSE ${PORT}
CMD [ "node", "." ]

我的package.json

​

代码语言:javascript
复制
{
  "name": "mockup",
  "version": "1.0.0",
  "description": "mockup",
  "keywords": [
    "loopback-application",
    "loopback"
  ],
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "engines": {
    "node": ">=10.16"
  },
  "scripts": {
    "build": "lb-tsc",
    "build:watch": "lb-tsc --watch",
    "lint": "npm run prettier:check && npm run eslint",
    "lint:fix": "npm run eslint:fix && npm run prettier:fix",
    "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
    "prettier:check": "npm run prettier:cli -- -l",
    "prettier:fix": "npm run prettier:cli -- --write",
    "eslint": "lb-eslint --report-unused-disable-directives .",
    "eslint:fix": "npm run eslint -- --fix",
    "pretest": "npm run clean && npm run build",
    "test": "lb-mocha --allow-console-logs \"dist/__tests__\"",
    "posttest": "npm run lint",
    "test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
    "docker:build": "docker build -t pcms-mockup .",
    "docker:run": "docker run -p 3000:3000 -d pcms-mockup",
    "migrate": "node ./dist/migrate",
    "openapi-spec": "node ./dist/openapi-spec",
    "prestart": "npm run build",
    "start": "node -r source-map-support/register .",
    "clean": "lb-clean dist *.tsbuildinfo .eslintcache"
  },
  "repository": {
    "type": "git"
  },
  "author": "",
  "license": "",
  "files": [
    "README.md",
    "dist",
    "src",
    "!*/__tests__"
  ],
  "dependencies": {
    "@loopback/authentication": "^4.2.8",
    "@loopback/authentication-jwt": "^0.4.2",
    "@loopback/authentication-passport": "^2.1.8",
    "@loopback/boot": "^2.3.4",
    "@loopback/core": "^2.9.0",
    "@loopback/openapi-v3": "^3.4.4",
    "@loopback/repository": "^2.8.0",
    "@loopback/rest": "^5.1.2",
    "@loopback/rest-explorer": "^2.2.5",
    "@loopback/service-proxy": "^2.3.3",
    "passport-http": "^0.3.0",
    "tslib": "^2.0.0"
  },
  "devDependencies": {
    "@loopback/build": "^6.0.0",
    "@loopback/eslint-config": "^8.0.2",
    "@loopback/testlab": "^3.1.8",
    "@types/node": "^10.17.26",
    "@types/passport-http": "^0.3.8",
    "eslint": "^7.3.1",
    "source-map-support": "^0.5.19",
    "typescript": "~3.9.5"
  }
}

​

在错误日志中,它提到了我不使用的环回连接器-mssql。我试着安装环回连接器-mssql(并保存到package.json)并再次构建映像,但是错误并没有消失。

您能帮我指出造成此错误的原因吗?

--加上6月30日-20日

我附加了我唯一的.datasource文件,它不包括mssql。

​

代码语言:javascript
复制
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
  name: 'db',
  connector: 'memory',
  localStorage: 'y',
  file: 'data/db.json',
};

// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
@lifeCycleObserver('datasource')
export class DbDataSource extends juggler.DataSource
  implements LifeCycleObserver {
  static dataSourceName = 'db';
  static readonly defaultConfig = config;

  constructor(
    @inject('datasources.config.db', {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

​

EN

回答 1

Stack Overflow用户

发布于 2020-06-29 06:36:33

当我将LB4应用程序文件夹(没有文件夹node_modules)复制到另一个位置并运行"npm && npm“时,我的错误与Docker报告的错误相同。这意味着我的问题是因为缺少我的代码所需的包“环回连接器-mssql”。我无法在代码中找到需要mssql的地方。我只在LoopBack 4教程的基础上添加身份验证。无论如何,在我安装了丢失的软件包后,它就可以工作了。

但是,我仍然不知道在我的代码中哪里需要mssql连接器>.<。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62630171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档