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

问题描述

我正在尝试将dynogels用作DynamoDB的ORM,但是我什至无法获得最简单的示例。无论我做什么,打字稿在尝试使用它时都会引发“无效的架构内容错误

运行命令

ts-node main.ts 

main.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 抛出新的错误(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.schema(/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/StackOverflowPost/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;

为我修复了该问题。