无法将 Saxon-JS 2 与 Webpack 一起使用

Posted

技术标签:

【中文标题】无法将 Saxon-JS 2 与 Webpack 一起使用【英文标题】:Unable to use Saxon-JS 2 with Webpack 【发布时间】:2021-03-01 00:04:55 【问题描述】:

我尝试将最新版本的 saxon-js 与 webpack 一起用作模块捆绑器 - 但尝试构建捆绑包会产生错误。 Saxon-js 是使用npm 安装的。

我已使用以下代码导入 saxon-js:

import * as SaxonJS from 'saxon-js';

还有

import SaxonJS from 'saxon-js';

在尝试以这种方式导入 saxon-js 时,webpack 会产生以下错误:

Module not found: Error: Can't resolve 'stream' in '/Users/bastian/Documents/Coding-Projekte/newversioningmachine/node_modules/saxon-js'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback:  "stream": require.resolve("stream-browserify") '
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback:  "stream": false 
 @ ./src/js/index.js 1:0-36

ERROR in ./node_modules/saxon-js/SaxonJS2N.js 4661:277-292
Module not found: Error: Can't resolve 'path' in '/Users/bastian/Documents/Coding-Projekte/newversioningmachine/node_modules/saxon-js'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback:  "path": require.resolve("path-browserify") '
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback:  "path": false 
 @ ./src/js/index.js 1:0-36

ERROR in ./node_modules/saxon-js/SaxonJS2N.js 4661:335-348
Module not found: Error: Can't resolve 'fs' in '/Users/bastian/Documents/Coding-Projekte/newversioningmachine/node_modules/saxon-js'
 @ ./src/js/index.js 1:0-36

我的问题可能与SaxonJS unusable with webpack有关

【问题讨论】:

【参考方案1】:

这是一个已知问题,请参阅https://saxonica.plan.io/issues/4669

我不完全理解这个问题,但仅 node.js 支持 Saxon-JS 的 npm 包,您最好使用浏览器版本。

【讨论】:

以上是关于无法将 Saxon-JS 2 与 Webpack 一起使用的主要内容,如果未能解决你的问题,请参考以下文章

如果 DOM classList 包含特定类,请检查 Saxon-JS 2.1

SaxonJS 无法与 webpack 一起使用

遍历 Saxon-JS 序列

Saxon-js 是不是对 xsl:param 执行 XML 语法检查?

如何在 Node 中使用 saxon-js 处理 XPath 表达式

使用 Saxon-JS 识别 XSLT 转换的性能瓶颈