繁体   English   中英

导入 CoreCompletionCore 时出现“类扩展值未定义不是构造函数或 null”

[英]"Class extends value undefined is not a constructor or null" when import CoreCompletionCore

代码:


import { InputStream, CommonTokenStream, Lexer, Token } from 'antlr4';
import antlr4 from 'antlr4';
import PrestoSqlLexer from '../lib/presto/PrestoSqlLexer';
import PrestoSqlParser from '../lib/presto/PrestoSqlParser';
import BaseParser from './common/baseParser';
import {CodeCompletionCore} from "antlr4-c3";


public suggest(sqlScript: string, atIndex?: number): AutocompleteOption[] {
    ...
    // core
    const core = new CodeCompletionCore(parser);
    // core.ignoredTokens = new Set([
    // ]);

    return [];
}

我有这样的错误

    TypeError: Class extends value undefined is not a constructor or null

       9 | } from './common/parserErrorListener';
      10 | import { AutocompleteOption } from './common/AutocompleteOption';
    > 11 | import { CodeCompletionCore } from 'antlr4-c3';
         | ^
      12 |
      13 | export default class PrestoSQL extends BaseParser {
      14 |     public createLexer(input: string): antlr4.Lexer {

      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/XPathLexer.ts:18:33)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/XPath.ts:16:1)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/index.ts:6:1)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/index.ts:18:1)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/index.ts:9:1)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4-c3-npm-2.2.1-db3ae1db96-8dd44825f3.zip/node_modules/antlr4-c3/src/CodeCompletionCore.ts:10:1)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4-c3-npm-2.2.1-db3ae1db96-8dd44825f3.zip/node_modules/antlr4-c3/index.ts:8:1)
      at Object.<anonymous> (src/parser/presto.ts:11:1)
      at Object.<anonymous> (src/parser/index.ts:3:1)
      at Object.<anonymous> (src/index.ts:1:1)

知道为什么吗? 谢谢

我试图更改导入语法,但失败了。

有人可以看一下吗? 谢谢。

这与打字稿版本有关吗?

顺便说一句,下面是 deps 版本

  "dependencies": {
    "@types/antlr4": "4.7.0",
    "antlr4": "^4.9.3",
    "antlr4-c3": "^2.2.1",
    "antlr4ts": "^0.5.0-alpha.4",
  },

更新

    TypeError: Class extends value undefined is not a constructor or null

      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/XPathLexer.ts:18:33)
      at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/XPath.ts:16:1)

tree/xpath/XPath.ts:16:1指向 rc/tree/xpath/XPathLexer.ts:18:33

但我没有在https://github.com/tunnelvisionlabs/antlr4ts/tree/0.5.0-alpha.4/src/tree/xpath中找到 XPatchLexer.ts

我的包安装有什么问题吗? 谢谢

但在我的 POC node_modules 中,我看到了 XPathLexer.d.js(请参阅随附的屏幕截图)

在此处输入图像描述

当您有无法自动解决的循环依赖时,通常会出现此错误。 查看错误跟踪。 它从 antlr4-c3 索引开始加载 C3 类,经过一些步骤并再次在 C3 类中结束,该类由显示的代码导入。 但是,我不清楚从 XPathLexer 到你的文件的步骤是如何发生的,但解决方案是直接导入你派生的类,而不是通过 lib 的索引文件使用快捷方式。

有关问题的更详细描述和解决方案,请参见如何在 JavaScript 和 TypeScript 中一劳永逸地解决讨厌的循环依赖问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM