简体   繁体   English

ArangoDB Foxx:require() 返回未定义

[英]ArangoDB Foxx: require() returned undefined

I created an ArangoDB Foxx service, and successfully mounted it on some route using Foxx CLI.我创建了一个 ArangoDB Foxx 服务,并使用 Foxx CLI 成功地将它挂载到某个路由上。 My service has a dependency which uses randombytes .我的服务有一个使用randombytes的依赖randombytes When I call the service it returns an error saying `randomBytes is not a function.当我调用该服务时,它返回一个错误,指出`randomBytes 不是一个函数。

For testing purposes I have created another service and just returned typeof require('randombytes') .出于测试目的,我创建了另一个服务并返回typeof require('randombytes') And it returned undefined .它返回了undefined

During installation Foxx CLI didn't warn me anything.在安装过程中 Foxx CLI 没有警告我任何东西。

Does anyone had such experience?有没有人有过这样的经历?

First, have you defined your randombytes module in your package.json dependencies ?首先,您是否在 package.json 依赖项中定义了 randombytes 模块?

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

Then what about然后呢

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

Actually I just tested ... and it returns "undefined" as well ... so not sure it's a valid module for arango.实际上我刚刚测试过……它也返回“未定义”……所以不确定它是否是 arango 的有效模块。

It's better to use arango's crypto methods最好使用 arango 的加密方法

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

I don't think that Foxx will alert you to missing dependencies, but it is important to make sure they are included in your ZIP package before installing your service/app.我不认为 Foxx 会提醒您缺少依赖项,但在安装服务/应用程序之前确保它们包含在您的 ZIP 包中很重要。

My project is organized like this:我的项目是这样组织的:

MyProject
   |-- foxx
       |-- service1
       |-- service2
       ...

I have a package.json file in the root of the project, as well as in each of the "service" folders.我在项目的根目录以及每个“服务”文件夹中有一个package.json文件。 My workflow (make) runs npm install inside each "service" folder before creating the ZIP archive.在创建 ZIP 存档之前,我的工作流程 (make) 在每个“服务”文件夹中运行npm install

Just make sure to include the node_modules folder and all should be happy.只要确保包含node_modules文件夹,一切都会很愉快。

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

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