typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Import behavior mismatch from typescript 5 (bwip-js)

Open ryanrasti opened this issue 6 months ago • 1 comments

I'm getting an issue where tsgo doesn't recognize an import that is working with normal tsc.

relevant versions:

{
  "dependencies": {
    "@typescript/native-preview": "^7.0.0-dev.20250529.1",
    "bwip-js": "^4.5.1",
    "typescript": "^5.8.3"
  }
}

To reproduce:

git clone https://github.com/ryanrasti/tsgo-import-mismatch-repro
cd tsgo-import-mismatch-repro
npm i

./node_modules/.bin/tsc # works fine

./node_modules/.bin/tsgo # get error "main.ts:1:23 - error TS2307: Cannot find module 'bwip-js' or its corresponding type declarations."

ryanrasti avatar May 29 '25 14:05 ryanrasti

I don't understand what's causing the issue, but if you add "include": ["node_modules"] to your tsconfig it'll work under tsgo

joshcartme avatar May 31 '25 03:05 joshcartme

Related: https://github.com/microsoft/typescript-go/issues/982

anilanar avatar Jun 03 '25 08:06 anilanar

Related: #982

Nice that seems to work for this example, but it has some side-effects -- e.g., now I run into an issue where I can't include graphql because node_modules/graphql/NotSupportedTSVersion.d.ts gets imported (underlying issue is that it seems that for a package.json in node_modules, typesVersions is no longer respected)

ryanrasti avatar Jun 05 '25 22:06 ryanrasti

Can you please file a new issue for your separate issue?

jakebailey avatar Jun 05 '25 23:06 jakebailey

Can you please file a new issue for your separate issue?

I didn't test if that is truly a separate issue (i.e., a mismatch between tsc and tsgo) -- I was just commenting that the proposed workaround has side-effects that make it not workable for me.

ryanrasti avatar Jun 08 '25 19:06 ryanrasti

Sorry, did not notice that you were the original issue filer. Adding that kind of include is definitely not an intended fix.

The problem here is that you have "moduleResolution": "Node" set, which implies module=commonjs, which then all together breaks things. This setup isn't supported by tsgo (and is not recommended in general).

If you instead change to nodenext resolution, your code compiles correctly.

jakebailey avatar Jun 26 '25 22:06 jakebailey

See also: https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html

jakebailey avatar Jun 26 '25 22:06 jakebailey