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

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

我正在尝试使用 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": "Whosebugpost",
  "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"
  }
}

当我运行我得到

WhosebugPost/node_modules/dynogels/node_modules/joi/node_modules/hoek/lib/index.js:740 throw new Error(msgs.join(' ') || 'Unknown error'); ^ Error: Invalid schema content: at Object.exports.assert (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/node_modules/hoek/lib/index.js:740:11) at Object.exports.schema (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/cast.js:55:10) at internals.Object.keys (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Object.exports.schema (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29) at internals.Object.keys (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Object.exports.schema (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29) at internals.Object.keys (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Joi.validate (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/lib/schema.js:121:71) at internals.Object._validateWithOptions (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/types/any/index.js:666:20) at module.exports.internals.Any.root.validate (/Users/stephencuzzort/Projects/WhosebugPost/node_modules/dynogels/node_modules/joi/lib/index.js:139:23)

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

找到问题了。这是 joi 版本不匹配。

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

导入

import * as Joi from "dynogels/node_modules/joi";

帮我修好了。