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

tsimp does not work with TypeScript v5.6.2 #29

Open
gfx opened this issue Sep 11, 2024 · 4 comments · May be fixed by #30
Open

tsimp does not work with TypeScript v5.6.2 #29

gfx opened this issue Sep 11, 2024 · 4 comments · May be fixed by #30

Comments

@gfx
Copy link

gfx commented Sep 11, 2024

Error messages in .tsimp/daemon/log:

TypeError: Cannot read properties of undefined (reading 'moduleResolution')
    at computeValue (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:21622:46)
    at importSyntaxAffectsModuleResolution (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:21599:28)
    at getDefaultResolutionModeForFileWorker (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:127780:10)
    at Object.getMode (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:124407:85)
    at Object.resolveTypeReferenceDirectiveReferences (file:///home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/tsimp/dist/esm/service/resolve-type-reference-directive-references.js:24:45)
    at resolveTypeReferenceDirectiveNamesWorker (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:125232:20)
    at resolveNamesReusingOldState (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:125354:14)
    at resolveTypeReferenceDirectiveNamesReusingOldState (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:125325:12)
    at processTypeReferenceDirectives (/home/goro/ghq/github.com/gfx/typescript-cookbook/node_modules/typescript/lib/typescript.js:126706:156)

It works with older TypeScript compilers, so it might be a regression in TypeScript.

djcsdy added a commit to softwareventures/observe-fs that referenced this issue Sep 11, 2024
v5.6.x is not compatible with tsimp.

tapjs/tsimp#29
@mattdean-digicatapult
Copy link

It looks to me like this was broken with microsoft/TypeScript#58825 which modified the implementation of the getMode method of typeReferenceResolutionNameAndModeGetter to take a third parameter of compilerOptions. I would not however consider this a typescript bug at first glance because the ResolutionNameAndModeGetter<FileReference | string, SourceFile | undefined> interface that the object implements has previously had getMode with that additional parameter.

I think the solution is just to pass compilerOptions in at the call to this method

const mode = loader.nameAndMode.getMode(

I'll try to put up a PR and see if the maintainers here agree

@FedericoBiccheddu
Copy link

Thank you @mattdean-digicatapult.

Until the PR get merged, I'm patching locally using the following patch with pnpm:

diff --git a/dist/esm/service/resolve-type-reference-directive-references.js b/dist/esm/service/resolve-type-reference-directive-references.js
index d285ff041190ba2cf2958b00831c089e175fd788..9f33eebec9a498afd0455331ba7aa10d7aa0de89 100644
--- a/dist/esm/service/resolve-type-reference-directive-references.js
+++ b/dist/esm/service/resolve-type-reference-directive-references.js
@@ -21,7 +21,7 @@ export const getResolveTypeReferenceDirectiveReferences = (host, moduleResolutio
         const loader = createLoader(containingFile, redirectedReference, options, host, resolutionCache);
         for (const entry of entries) {
             const name = loader.nameAndMode.getName(entry);
-            const mode = loader.nameAndMode.getMode(entry, containingSourceFile);
+            const mode = loader.nameAndMode.getMode(entry, containingSourceFile, options);
             const key = createModeAwareCacheKey(name, mode);
             let result = rtrdrInternalCache.get(key);
             if (!result) {

@krutoo
Copy link

krutoo commented Sep 16, 2024

same issue

@stuft2
Copy link

stuft2 commented Sep 19, 2024

fwiw, this bug makes the node test runner appear to pass the tests when they should fail.

// fail.ts
import { test } from 'node:test'
import { strict as assert } from 'node:assert'

test('should fail', t => {
    assert.fail('should fail')
})

running the following command

# Node.js v22.9.0
node --import=tsimp/import --test fail.ts

outputs

✔ fail.ts (1365.779513ms)
ℹ tests 1
ℹ suites 0
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 1379.271959

EDIT: it appears to fail silently on all usages, not just in the test runner.

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

Successfully merging a pull request may close this issue.

5 participants