繁体   English   中英

即使使用 github 回购中的示例,dynogels 总是告诉我无效的架构内容

[英]dynogels always tells me Invalid schema content even when using examples from it's github repo

我正在尝试将dynogels用作 DynamoDB 的 ORM,但我什至无法使用最简单的示例。 无论我做什么,typescript 在我尝试使用它时都会抛出“无效的架构内容”错误。

运行命令

ts-node main.ts 

主.ts

import * as Dynogels from "dynogels";
import * as Joi from "joi";

// this comes out of an example on the dynogels github page
var BlogPost = Dynogels.define('BlogPost', {
  hashKey : 'email',
  rangeKey : 'title',
  schema : {
    email   : Joi.string().email(),
    title   : Joi.string(),
    content : Joi.string(),
    tags   : Dynogels.types.stringSet(),
  }
});

console.log("this doesn't work")

package.json

{
  "name": "stackoverflowpost",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/dynogels": "^9.0.3",
    "@types/joi": "^14.3.4",
    "dynogels": "^9.1.0",
    "joi": "^17.2.0",
    "typescript": "^3.9.7"
  }
}

当我跑步时,我得到

StackOverflowPost/node_modules/dynogels/node_modules/joi/node_modules/hoek/lib/index.js:740 throw new Error(msgs.join(' ') || '未知错误'); ^ 错误:无效的架构内容:在 Object.exports.assert(/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/node_modules/hoek/lib/index.js:740:11)在 Object.exports。模式(/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:55:10)在 internals.Object.keys(/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules /joi/lib/types/object/index.js:352:35) 在 Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29 ) 在 internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) 在 Object.exports.schema (/Users/stephencuzzort /Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29) 在 internals.Object.keys (/Users/stephencuzzort/Projects/StackO verflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) 在 Joi.validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/lib/schema.js:121: 71) 在 internals.Object._validateWithOptions (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/any/index.js:666:20) 在 module.exports.internals.Any.root .validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/index.js:139:23)

为什么即使我使用 github 页面中的示例,我仍然会收到此消息? 我怎样才能让这个例子起作用?

发现了问题。 这是joi版本不匹配。

您需要确保joi版本完全匹配,或者从 dynogels node_modules 导入

从“dynogels/node_modules/joi”导入 * 作为 Joi;

帮我修好了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM