I am trying antlr4ts-sql in my project, which is part of monorepo using jazelle, typescript, yarn pnp.
Versions are:
% jz version
actual: 0.0.0-standalone.82
system: 0.0.0-standalone.74
% yarn -v
3.3.0
My codes (from antlr4ts-sql repo):
import { antlr4tsSQL, SQLDialect } from 'antlr4ts-sql';
export class Experiment {
public exp() {
const antlr4tssql = new antlr4tsSQL(SQLDialect.MYSQL);
const query = 'SELECT * FROM table1';
const parseTree = antlr4tssql.getParseTreeFromSQL(query);
console.log(parseTree);
}
}
but I got the following errors:
TypeError: Class extends value undefined is not a constructor or null
> 1 | import { antlr4tsSQL, SQLDialect } from 'antlr4ts-sql';
| ^
2 |
3 |
4 | export class Experiment {
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/antlr4ts-sql-npm-1.1.0-d18d4988c9-79289d09ea.zip/node_modules/antlr4ts-sql/index.ts:1:1)
at Object.<anonymous> (src/autocomplete/experiments.ts:1:1)
at Object.<anonymous> (src/autocomplete/index.ts:2:1)
at Object.<anonymous> (src/index.ts:1:1)
at Object.<anonymous> (__tests__/autocomplete/antlr4ts-sql.test.ts:1:1)
at module.exports (../../../../../common/@company/jest-config-utils/test-runner.js:19:44)
when I unzip antlr4ts-sql-npm-1.1.0-d18d4988c9-79289d09ea.zip
from .yarn/cache
, I got the following:
it seems that there are XPathLexer.js
and XPathLexer.d.ts
in the unzip node_modules/dist/tree/xpath
(which are Generated from XPathLexer.g4 by ANTLR 4.7.3-SNAPSHOT). but from the error message, test-runner.js is looking for at Object.<anonymous> (../../../../../../.yarn/cache/antlr4ts-npm-0.5.0-dev-7e0fc8988a-640dae2229.zip/node_modules/src/tree/xpath/XPathLexer.ts:18:33)
but XPathLexer.ts
does not exist in the source code and does not exist in the antlr4ts-sql-npm-1.1.0-d18d4988c9-79289d09ea.zip
of .yarn/cache
I am new to yarn pnp, not sure whether this is expected. My understanding is that jest
should read antlr4ts-sql and antlr4ts from the zip file, but the errors means that they are not reading the zip files.
I guess something wrong with my deps and config.
tsconfig.json is
{
"compilerOptions": {
"noEmit": true,
"target": "ES6",
"module": "CommonJS",
"lib": [
"es6"
],
"isolatedModules": true,
"allowJs": true,
"checkJs": true,
"jsx": "react",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"baseUrl": ".",
"resolveJsonModule": true,
"declaration": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"importHelpers": true
},
"include": [
"src/**/*.*",
"__tests__/**/*.ts"
]
}
package.json is
...
"dependencies": {
"antlr4ts-sql": "^1.1.0",
"assert": "1.5.0",
"tslib": "^2.1.0",
"jest-pnp-resolver": "1.2.3"
},
"devDependencies": {
"@types/jest": "^26.0.24",
"babel-eslint": "10.1.0",
"babel-jest": "28.1.3",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.3",
"jest-environment-jsdom-global": "3.1.2",
"patch-package": "6.2.2",
"prettier": "^2.8.0",
},
...
I am stuck in this question for several days. Any comments welcomed. thanks