在电子应用程序中使用libxml-xsd失败,并出现绑定错误

我想根据电子应用程序中的模式来validationXML文件。

在包含我的libxml-xsd require语句之前,我有一个angular2服务。 只要我把它添加到我的服务文件的顶部:

const xsd = require('libxml-xsd'); 

我运行npm run build执行此:

 webpack --progress --profile --colors --display-error-details --display-cached 

我在输出中看到以下新警告:

 WARNING in ./~/bindings/bindings.js Critical dependencies: 76:22-40 the request of a dependency is an expression 76:43-53 the request of a dependency is an expression @ ./~/bindings/bindings.js 76:22-40 76:43-53 WARNING in ./~/bindings/README.md Module parse failed: /Users/myusername/Documents/Personal/MyApp/node_modules/bindings/README.md Unexpected token (2:3) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:3) at Parser.pp$4.raise (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:2221:15) at Parser.pp.unexpected (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:603:10) at Parser.pp$3.parseExprAtom (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1822:12) at Parser.pp$3.parseExprSubscripts (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1715:21) at Parser.pp$3.parseMaybeUnary (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1692:19) at Parser.pp$3.parseExprOp (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1656:43) at Parser.pp$3.parseExprOp (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1658:21) at Parser.pp$3.parseExprOps (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1639:17) at Parser.pp$3.parseMaybeConditional (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1620:21) at Parser.pp$3.parseMaybeAssign (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1597:21) at Parser.pp$3.parseExpression (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:1573:21) at Parser.pp$1.parseStatement (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:727:47) at Parser.pp$1.parseTopLevel (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:638:25) at Parser.parse (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:516:17) at Object.parse (/Users/myusername/Documents/Personal/MyApp/node_modules/acorn/dist/acorn.js:3098:39) at Parser.parse (/Users/myusername/Documents/Personal/MyApp/node_modules/webpack/lib/Parser.js:902:15) at DependenciesBlock.<anonymous> (/Users/myusername/Documents/Personal/MyApp/node_modules/webpack/lib/NormalModule.js:104:16) at DependenciesBlock.onModuleBuild (/Users/myusername/Documents/Personal/MyApp/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10) at nextLoader (/Users/myusername/Documents/Personal/MyApp/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25) at /Users/myusername/Documents/Personal/MyApp/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5 at Storage.finished (/Users/myusername/Documents/Personal/MyApp/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16) at /Users/myusername/Documents/Personal/MyApp/node_modules/graceful-fs/graceful-fs.js:78:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3) @ ./~/bindings ^\.\/.*$ 

然后通过执行: electron main.js来运行我的应用程序,然后在浏览器控制台中引发此错误:

 Uncaught Error: Could not locate the bindings file. Tried: → /Users/myusername/Documents/Personal/MyApp/build/xmljs.node → /Users/myusername/Documents/Personal/MyApp/build/Debug/xmljs.node → /Users/myusername/Documents/Personal/MyApp/build/Release/xmljs.node → /Users/myusername/Documents/Personal/MyApp/out/Debug/xmljs.node → /Users/myusername/Documents/Personal/MyApp/Debug/xmljs.node → /Users/myusername/Documents/Personal/MyApp/out/Release/xmljs.node → /Users/myusername/Documents/Personal/MyApp/Release/xmljs.node → /Users/myusername/Documents/Personal/MyApp/build/default/xmljs.node → /Users/myusername/Documents/Personal/MyApp/compiled/6.5.0/darwin/x64/xmljs.node 

有人可以帮我在我的应用程序configuration下运行libxml-xsd吗? 这与webpack有什么关系? 如果是这样 – 我如何改变它的configuration来引入适当的文件?

您可以使用GitHub问题中的代码解决bindings.js 问题 。

的WebPack

 module.exports = { plugins: [ new webpack.IgnorePlugin(/^mock-firmata$/), new webpack.ContextReplacementPlugin(/bindings$/, /^$/) ], externals: ["bindings"] } 

问题是libxml-xsd包是用于服务器端的。 我想你会在这之后得到另一个问题。 它有这样的依赖关系require('fs'); 不能用于前端。

我认为你需要在包含native模块的文件夹上使用asar-unpack或者asar-unpack-dir参数。

看起来只需要一个string,请参阅asar-unpack-dir的API文档以查看glob示例。 (一个string限制似乎是一个模块限制,如果你认为它应该作为一个数组,你需要在他们的仓库中提出一个问题。)