[英]I have produced a parser.js file using PEG.js, however I get an import error when linking to HTML. Help in solving this would be appreciated
我已經使用 peg.js 在線工具成功生成了 parser.js 文件。 我已使用以下方法將其鏈接到我的 html 文件:
<script src="parser.js"></script>
我打算從我的腳本運行parser.parse(txt)
但是我得到ReferenceError: module is not defined from the first line of parser.js which is module.exports =
查看文檔后,我認為這與沒有安裝 node.js 有關,盡管我正在使用 REPL 運行我的測試,我認為無論如何安裝了 node.js。
有沒有辦法通過導入 js 模塊而不必安裝 node.js 來運行它,如果是這樣的話怎么辦?
如果對任何人有用,我可以在這里回答我自己的問題:
我可以將 parser.js 的開頭行從module.exports
為var myparser =
。
因此,我現在可以成功運行myparser.parse(txt)
。 不需要 node.js 或導入語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.