我在向NodeJS应用程序导入SaxonJS时遇到问题。
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不是函数
怎么一回事?
发布于 2020-09-15 03:48:41
试一试
require('SaxonJS2N.js')我想您已经选择了浏览器版本的Saxon-JS,而不是Node.js版本。
发布于 2021-02-24 06:17:53
我遇到了同样的错误,并能够通过将以下代码添加到我的package.json文件中来解决它。这使得Jest使用节点环境而不是jsdom (默认):
"jest": { "testEnvironment": "node" }
https://jestjs.io/docs/en/configuration#testenvironment-string
https://stackoverflow.com/questions/63888854
复制相似问题