Not resolving to the right export
We are using https://www.npmjs.com/package/markdown-to-jsx in our project. And import a namespace from it via:
import type { MarkdownToJSX } from 'markdown-to-jsx'`
With "typescript": "5.8.3" things work as expected.
With "@typescript/native-preview": "^7.0.0-dev.20250522.2", there's the following error:
Module '"/Users/.../my-repo/node_modules/markdown-to-jsx/dist/index.cjs"' has no exported member 'MarkdownToJSX'. Did you mean to use 'import MarkdownToJSX from "/Users/.../my-repo/node_modules/markdown-to-jsx/dist/index.cjs"' instead?
import type { MarkdownToJSX } from 'markdown-to-jsx';
Checking markdown-to-jsx's "exports", things look reasonable enough:
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"node": "./dist/index.module.js",
"default": "./dist/index.modern.js"
},
"require": {
"types": "./dist/index.cjs.d.ts",
"default": "./dist/index.cjs"
}
}
},
It looks suspicious that tsgo tries to resolve to CJS files, and not ESM.
For ref, here's our repo's full TSconfig:
TSconfig
{
"compilerOptions": {
// type checking
"strict": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": false,
"noUncheckedIndexedAccess": false,
"noImplicitAny": false,
// modules
"baseUrl": "./",
"module": "Preserve",
"moduleResolution": "bundler",
"paths": {
"MODULES/*": ["./src/modules/*"],
"UTILS/*": ["./src/utils/*"],
"LEGACY/*": ["./src/LEGACY/*"],
"SRC/*": ["./src/*"]
},
"resolveJsonModule": true,
// emit
"noEmit": true,
// JS support
"allowJs": false,
// interop
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"verbatimModuleSyntax": false,
// language and environment
"target": "es2021",
"lib": ["dom", "dom.iterable", "esnext"],
"jsx": "react-jsx",
// completeness
"skipLibCheck": true
},
"exclude": ["node_modules", "cypress", "coverage", "build"],
"include": [
"./@types/**/*.ts",
"./src/**/*.ts",
"./src/**/*.tsx",
"node_modules/vitest/globals.d.ts",
"./playwright"
]
}
This might be the same issue as described here: https://github.com/microsoft/typescript-go/issues/895#issuecomment-2899289082
See #904.
This package is broken: https://arethetypeswrong.github.io/?p=markdown-to-jsx%407.7.8
I'm not surprised that this fails to work. That being said, is the tsconfig that breaks really one with moduleResolution=bundler? @abstractalgo
is the tsconfig that breaks really one with
moduleResolution=bundler?
Yes, it is. (I've posted the full TSconfig in the first comment, at the end of it) cc @jakebailey
Reading https://app.unpkg.com/[email protected]/files/dist/index.cjs.d.ts, I do not see MarkdownToJSX exported. Also, index.cjs.d.ts is not the right extension for that file either, it should be index.d.cts, and not contain ESM syntax, so that's wrong too. I'm not sure what tool they're using to generate these files, but that tool is definitely broken.
That being said, I tried making my own repro and saw no difference between tsc and tsgo. https://github.com/jakebailey/tsgo-repro-916
So, we would need a repro that shows the problem to be able to look at this.