Cannot import from .d.ts files
We try and import a type:
the file is a .d.ts
and it exports what we want to import:
tsc does this fine but tsgo gives an error:
utils/forgeRock/middlewares.ts:5:8 - error TS2307: Cannot find module '@forgerock/javascript-sdk/dist/config/interfaces' or its corresponding type declarations.
5 } from '@forgerock/javascript-sdk/dist/config/interfaces';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
im getting this same problem i think with react-instantsearch package, latest ver
im trying
import {Hits} from 'react-instantsearch';
Hits;
and getting
main.tsx:1:20 - error TS2307: Cannot find module 'react-instantsearch' or its corresponding type declarations.
1 import {Hits} from 'react-instantsearch';
~~~~~~~~~~~~~~~~~~~~~
Found 1 error in main.tsx:1
tsc no errors
moduleResolution: node is removed and it's internally remapped to moduleResolution: bundler (I got this info from @jakebailey). This means that package.json#exports are always interpreted when they are present in package.json and this field is meant to expose everything from the package that is meant to be exposed. Everything else is considered private and inaccessible.
@lukpsaxo @forgerock/javascript-sdk doesnt expose dist in its exports
@mattlewis92 Similarly, libphonenumber-js doesn't expose types in its exports
Both of those can fail with moduleResolution: node16 (and newer values too) in Strada
@elee1766 I can't repro any issue with react-instantsearch, could you recheck if you are still affected by the recent preview builds?
Is there any work around ?
It’s going to be chaos I the ecosystem asking authors to re export types from their index everywhere.
I will raise issues for the packages where it affects us.
Sorry it seems most of our cases they were exposed somehow already e.g. forgerock sdk exports src/* -> dist/* so changing the imports to a src file made it work, it just takes some digging :)
@mattlewis92 Similarly, libphonenumber-js doesn't expose types in its exports
Ah I see, I did try setting moduleResolution: "bundler" but tsc still compiled OK. After a bit of trial and error I found a typeRoots: ["node_modules"] entry in the tsconfig that was somehow making it compile with tsc 🤷♂ Removing that, and I now get consistent errors between tsc and tsgo 🥳
So, it seems like everything is actually working correctly? (Where correctly means "node10 resolution is unsupported, use bundler"?)
@jakebailey yes, happy to close, though it might avoid some noise to print a error “falling back to bundler module resolution which might cause some import errors, see xyz”
Yes, we generally speaking are missing all of the "program errors" which complain about deprecated / bad options. This would be one thing we should report. Though, I think by the time we get there, it might be too late to realize we've remapped the options...
Filed #982.