0

我在将 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 不是函数

到底是怎么回事?

4

2 回答 2

0

我遇到了同样的错误,并且能够通过将以下内容添加到我的 package.json 文件来解决它。这使得 Jest 使用节点环境而不是 jsdom(默认):

"jest": { "testEnvironment": "node" }

https://jestjs.io/docs/en/configuration#testenvironment-string

于 2021-02-23T22:17:53.263 回答
0

尝试

require('SaxonJS2N.js')

我认为您选择了 Saxon-JS 的浏览器版本,而不是 Node.js 版本。

于 2020-09-14T19:48:41.333 回答