node.js - NodeJS 中的 SaxonJS
问题描述
我在将 SaxonJS 导入 NodeJS 应用程序时遇到问题。
const saxonJs = require("saxon-js");
console.log(Object.getOwnPropertyNames(saxonJs));
// [ ]
console.log(Object.getOwnPropertyNames(window.SaxonJS));
/**
[
'atom', 'Atomic',
'transform', 'Serializer',
'serialize', 'StringWriter',
'getProcessorInfo', 'getResource',
'setLogLevel', 'getLogLevel',
'setPlatform', 'getPlatform',
'getNavigator', 'timeStamp',
'internalTransform', 'checkOptions',
'makeAtomicValue', 'getItemDetails',
'XdmArray', 'XdmFunction',
'XdmMap', 'U',
'XError', 'XPath',
'XS', 'Developer'
]
*/
const testOutput = saxonJs.transform({
stylesheetFileName: xslt_filepath,
sourceFileName: source_filename,
destination: 'raw',
});
// returns TypeError: saxonJs.transform is not a function
window.SaxonJS.transform({
stylesheetFileName: xslt_filepath,
sourceFileName: inputFiles[j],
destination: 'raw',
});
// XError: Cannot supply stylesheetFileName in browser
返回 TypeError: saxonJs.transform 不是函数
到底是怎么回事?
解决方案
我遇到了同样的错误,并且能够通过将以下内容添加到我的 package.json 文件来解决它。这使得 Jest 使用节点环境而不是 jsdom(默认):
"jest": { "testEnvironment": "node" }
https://jestjs.io/docs/en/configuration#testenvironment-string
推荐阅读
- c++ - 如何使用这个受保护的成员函数来获得想要的输出
- haskell - haskell 无法将预期类型与实际类型“Bool”匹配
- javascript - Redux 表单状态未定义
- c++ - Microsoft C++ 和 g++ 预处理器行为差异
- python-3.x - XML 到 Pandas 数据框 - 重塑数据
- vue.js - 自定义 vuetify v-calendar 日期名称
- javascript - Ajax 请求不传递整个字符串?
- solidity - 为什么声明返回类型字节内存会产生编译器错误?
- android - 是否可以通过 android 使用 termux 编译 C++ 库?
- reactjs - 将多个对象传递给 axios 发布请求,但它不起作用