ArangoDB Foxx:require()返回未定义

问题描述 投票:0回答:1

我创建了一个ArangoDB Foxx服务,并使用Foxx CLI在某个路由上成功安装了它。我的服务具有使用randombytes的依赖项。当我调用该服务时,它返回一条错误消息,指出`randomBytes不是一个函数。

出于测试目的,我创建了另一个服务,并刚刚返回typeof require('randombytes')。然后返回undefined

在安装过程中,Foxx CLI没有警告我任何东西。

有人有过这样的经历吗?

arangodb foxx
1个回答
0
投票

首先,您是否在package.json依赖项中定义了randombytes模块?

{
  "private": true,
  "dependencies": {
    "randombytes": "2.1.0"
  }
}

然后呢

let randombytes = require('randombytes');
console.log(randomBytes(16));

实际上我刚刚测试过……它也返回“ undefined”……所以不确定它是否是arango的有效模块。

最好使用arango的加密方法

https://www.arangodb.com/docs/stable/appendix-java-script-modules-crypto.html#genrandomnumbers

© www.soinside.com 2019 - 2024. All rights reserved.