如果出现 fs 错误,如何使用 antlr? [英] How to use antlr if an error with fs occurs?

查看:37
本文介绍了如果出现 fs 错误,如何使用 antlr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上对 antlr 有问题.我在 Visual Studio 代码中使用 angular.我知道如何在项目中包含和编写语法.但是,现在我遇到了启动时出错的问题:

I have actually a problem with antlr. I use angular in visual studio code. I know how to include and write a grammar in a project. However, now I faced the problem that an error occurs while starting it:

"./node_modules/antlr4/CharStreams.js 中的错误找不到模块:错误:无法解析 'C:\Users\simon\antlrTestProject\node_modules\antlr4' 中的 'fs'./node_modules/antlr4/FileStream.js 中的错误找不到模块:错误:无法解析 'C:\Users\simon\antlrTestProject\node_modules\antlr4' 中的 'fs'"

"ERROR in ./node_modules/antlr4/CharStreams.js Module not found: Error: Can't resolve 'fs' in 'C:\Users\simon\antlrTestProject\node_modules\antlr4' ERROR in ./node_modules/antlr4/FileStream.js Module not found: Error: Can't resolve 'fs' in 'C:\Users\simon\antlrTestProject\node_modules\antlr4'"

我发现 fs 在 angular 6+ 中不再可用.不幸的是,我发现无法解决这个问题.

I found out that fs is no longer available in angular 6+. Unfortunetly I found no possibility to solve this.

推荐答案

为了在 node.js 之外使用 ANTLR JavaScript 运行时,您需要配置 webpack 以排除某些存在于 node.js 中但不在 node.js 中的模块浏览器.来自 文档:

In order to use the ANTLR JavaScript runtime outside of node.js, you need to configure webpack to exclude certain modules that exist in node.js, but not in the browser. From the docs:

在 webpack.config 文件中,仅使用以下命令排除 node.js 模块:node: { module: "empty", net: "empty", fs: "empty" }

in the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" }

这篇关于如果出现 fs 错误,如何使用 antlr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆