Closed yamachu closed 2 years ago
Can you paste some error logs?
thanks @JounQin
here is error log
# ~/Projects/github.com/yamachu/remark-types-broken-repro $ [master]
yarn run typecheck
yarn run v1.22.19
$ tsc --noEmit
node_modules/remark-parse/lib/index.d.ts:3:26 - error TS2307: Cannot find module 'mdast-util-from-markdown/lib' or its corresponding type declarations.
3 options: void | import('mdast-util-from-markdown/lib').Options | undefined
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in node_modules/remark-parse/lib/index.d.ts:3
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
There is indeed a lib/index.d.ts
for mdast-util-from-markdown
, maybe you have different and incompatible mdast-util-from-markdown
versions installed.
https://unpkg.com/browse/mdast-util-from-markdown@1.2.0/lib/index.d.ts
I'll check your reproduction soon.
OK, it should be related to exports
field from mdast-util-from-markdown
.
yes, it's related to exports.
https://github.com/syntax-tree/mdast-util-from-markdown/issues/29 This Issue seems reluctant to add to export.
https://github.com/yamachu/remark/tree/fix-lib-types
With these changes, it worked in my environment. I have searched a bit for a compile option to see if it is possible to make the import path less deep, but have not found it yet...
You are using the TypeScript compiler options "module": "node16"
and "moduleResolution": "node16"
(the latter is redundant if the former is specified). Those are the correct TypeScript options to use since TypeScript 4.7, but not all packages are using / supporting this yet, including remark apparently.
remark-parse
is doing this correctly:
However, TypeScript generates:
/** @type {import('unified').Plugin<[Options?] | void[], string, Root>} */
export default function remarkParse(options: void | import("mdast-util-from-markdown/lib").Options | undefined): void;
export type Root = import('mdast').Root;
export type Options = import('mdast-util-from-markdown').Options;
If we use "module": "node16"
, it’s even worse.
/** @type {import('unified').Plugin<[Options?] | void[], string, Root>} */
export default function remarkParse(options: void | import("../../../node_modules/mdast-util-from-markdown/lib/index.js").Options | undefined): void;
export type Root = import('mdast').Root;
export type Options = import('mdast-util-from-markdown').Options;
This appears to be a TypeScript bug (causing bugs in our output. This is definitely a bug in remark’s published packages).
@remcohaszing I remember there was a similar issue somewhere, and that it was also reported (by you?) over at TypeScript?
Nope, doesn't ring a bell.
OK well I am not sure what to search for but I am pretty sure you commented on exactly this issue in one of the TypeScript repos and linked it
@yamachu unfortunately the only workaround / solution I see so far is to use "skipLibCheck": true
.
I think that’s the issue causing this indeed. Hard to believe such a critical issue has been open for over 2 years :confused:
I then solved this problem with the following settings.
tsconfig.json
"baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"paths": {
"mdast-util-from-markdown/lib": [
"node_modules/mdast-util-from-markdown/lib/index.d.ts"
]
},
Initial checklist
Affected packages and versions
remark-parse 10.0.1
Link to runnable example
No response
Steps to reproduce
https://github.com/yamachu/remark-types-broken-repro
npx tsc --noEmit
for running type checkREPRO
Expected behavior
Pass type check without error
Actual behavior
Fail type check with error
Runtime
Node v16
Package manager
yarn 1
OS
macOS
Build and bundle tools
Other (please specify in steps to reproduce)