Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] TypeScript broken #3891

Closed
kaby76 opened this issue Dec 14, 2023 · 2 comments
Closed

[build] TypeScript broken #3891

kaby76 opened this issue Dec 14, 2023 · 2 comments

Comments

@kaby76
Copy link
Contributor

kaby76 commented Dec 14, 2023

Testing of the TypeScript target is broken.

Tests fail with import module problem.

$ bash run.sh ../hw-examples/alter_operator.sql
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\msys64\home\Kenne\issues\g4-3890\sql\plsql\Generated-TypeScript-hw\PlSqlLexerBase' imported from C:\msys64\home\Kenne\issues\g4-3890\sql\plsql\Generated-TypeScript-hw\PlSqlLexer.js
Did you mean to import ../PlSqlLexerBase.js?
    at finalizeResolution (node:internal/modules/esm/resolve:255:11)
    at moduleResolve (node:internal/modules/esm/resolve:908:10)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at nextResolve (node:internal/modules/esm/hooks:865:28)
    at resolve (C:\Users\kenne\AppData\Roaming\npm\node_modules\ts-node\dist\child\child-loader.js:15:125)
    at nextResolve (node:internal/modules/esm/hooks:865:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:303:30)
    at handleMessage (node:internal/modules/esm/worker:196:24)
    at Immediate.checkForMessages [as _onImmediate] (node:internal/modules/esm/worker:138:28)
    at process.processImmediate (node:internal/timers:478:21) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///C:/msys64/home/Kenne/issues/g4-3890/sql/plsql/Generated-TypeScript-hw/PlSqlLexerBase'
}

6 days ago, MS released a new package for typescript and things haven't worked well since. Unfortunately I can't find a rollback state that does work.

I am able to get the target to work if I add a ".js" suffix for the file import in the generated .ts file. But that is not a good solution. Filed an Issue in the Antlr4 repo as to why some import have ".js" and others do not. I'm not sure whether there are settings in the tsconfig.json to fix the problem.

antlr/antlr4#4491

@kaby76
Copy link
Contributor Author

kaby76 commented Dec 15, 2023

Apparently, this can be fixed if the entire code is placed in a package. The inconsistency in the tool has been fixed. antlr/antlr4#4492

@mike-lischke
Copy link
Member

Note here that this is the result of going ESM. ES modules are used in browsers, which have no search strategy like Node.js (where CommonJS was invented before browsers had module support). Browsers always required to have the full file name, including the extension to be specified for a module. Now that Node.js also supports ESM a new setting was introduced ("Node16") by TS that enforces an explicit extension in TS source code for imports.

In the mid run I expect ESM to completely take over as this is supported by both major parties (browsers + Node.js), so it's a good idea to get used to the fact that the extension is necessary in imports. At least if you don't use a bundler (like esbuild or webpack), which would take care for that (and for which a different TS setting exists).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants