(请原谅我的术语错误,因为我是JS和MarkLogic的新手,但是如果我在某个地方错了,请纠正我。)。
我想导入一个BigNumber对象(或者它是一个类,构造..)从外部模块bignumber.js中使用MarkLogic q控制台(服务器端JS)。
这是从他们的github建议的方式,但它是针对Node.js而不是SSJS的。https://github.com/MikeMcl/bignumber.js/
const BigNumber = require('bignumber.js');
import BigNumber from "bignumber.js";
import { BigNumber } from "bignumber.js";到目前为止,我的设置是这样的:
我打开了
my-db-modules
我使用以下行将bignumber.js文档插入到my-db-modules中:
declareUpdate();
xdmp.documentLoad('path/bignumber.js', {'uri': 'bignumber.js'});我也插入了bignumber.mjs文件。
当我试图从BigNumber文件导入.js时,我得到的是'Module‘,如果我尝试从.mjs文件导入它,我得到的文档不是可执行的mimetype. URI: bignumber.mjs'。
我找到了关于如何使用模块db:https://docs.marklogic.com/guide/admin/databases#id_38484的这一节。
但我不知道是否正确,因为我尝试将HTTP的根更改为http://marklogic.com/,但没有结果。
发布于 2021-05-03 16:41:09
正如MadsHansen在注释中指出的那样,应该在其名称中插入带前导斜杠的注释文档。
我只想澄清下一部分:
使用
require处理.js文件const BigNumber = require('/bignumber.js');.mjs文件import BigNumber from "/bignumber.mjs";
import { BigNumber } from "/bignumber.mjs";.js和.mjs文件都应该插入到模块db中,并在主数据库中使用。
我用以下行加载了文件:
xdmp.documentLoad('path/bignumber.js', {'uri': '/bignumber.js'});
xdmp.documentLoad('path/bignumber.mjs', {'uri': '/bignumber.mjs'});https://stackoverflow.com/questions/67370149
复制相似问题