Open umajho opened 11 months ago
Well, I found the problem. It is my fault. I should set:
"module": "NodeNext",
"moduleResolution": "NodeNext",
in tsconfig.json.
I just noticed that when I set
"module": "NodeNext",
"moduleResolution": "NodeNext",
in tsconfig.json, it just make the command not complain, but the generated .d.ts
is wrong.
pnpm run build-bar-dts-resolve
generated definition file:
import { Foo } from './foo.js'; // Cannot find module './foo.js' or its corresponding type declarations.ts(2307)
declare const baz: Foo;
export { baz };
I face the same problem, need somebody to help
I'm also running into this - were you able to find a solution?
Also hitting this issue within a monorepo where I am trying to bundle an unpublished internal library package into a published one. This internal library is listed under noExternal
and while the bundling is working just fine, the dts generation was leaving those imports as if they were external. Enabling dts resolve is now causing this issue :(
If a package points a subpath export (
exports: { "./a": "./a.ts" }
in package.json) to a TypeScript file (“a.ts”:import {…} from "./b.ts"
), and you use that package as a dependency, when you run tsup withdts: { resolve: true }
: the file (“a.ts”) itself is treated as TypeScript code, but TypeScript files (like “b.ts”) imported by the former file are treated as plain JavaScript codes.If “a.ts” is set as the main export (
exports: { ".": "./ts" }
), everything works.Reproduction
https://github.com/umajho/tsup-reproduction-dts-resolve-pnpm-workspace
in “packages/support-lib”:
cd packages/lib-to-be-built
pnpm run build-foo-dts-resolve
⭕️Importing from “support-lib” with the subpath “./foo”, and building the library using tsup with
dts: { resolve: true }
:success
``` ➜ lib-to-be-built git:(main) pnpm run build-foo-dts-resolve > @tsup-reproduction-dts-resolve-pnpm-workspace/lib-to-be-built@1.0.0 build-foo-dts-resolve /private/tmp/test/packages/lib-to-be-built > tsup --config tsup.foo-dts-resolve.config.ts CLI Building entry: lib-imports-foo.ts CLI Using tsconfig: tsconfig.json CLI tsup v7.2.0 CLI Using tsup config: /private/tmp/test/packages/lib-to-be-built/tsup.foo-dts-resolve.config.ts CLI Target: es2020 CLI Cleaning output folder ESM Build start ESM dist/lib-imports-foo.js 98.00 B ESM ⚡️ Build success in 10ms DTS Build start DTS ⚡️ Build success in 474ms DTS dist/lib-imports-foo.d.ts 60.00 B ```pnpm run build-bar-using-main-dts-resolve
⭕️Importing from “support-lib” with the main path, and building the library using tsup with
dts: { resolve: true }
:success
``` ➜ lib-to-be-built git:(main) pnpm run build-bar-using-main-dts-resolve > @tsup-reproduction-dts-resolve-pnpm-workspace/lib-to-be-built@1.0.0 build-bar-using-main-dts-resolve /private/tmp/test/packages/lib-to-be-built > tsup --config tsup.bar-using-main-dts-resolve.config.ts CLI Building entry: lib-imports-bar-using-main.ts CLI Using tsconfig: tsconfig.json CLI tsup v7.2.0 CLI Using tsup config: /private/tmp/test/packages/lib-to-be-built/tsup.bar-using-main-dts-resolve.config.ts CLI Target: es2020 CLI Cleaning output folder ESM Build start ESM dist/lib-imports-bar-using-main.js 109.00 B ESM ⚡️ Build success in 12ms DTS Build start DTS ⚡️ Build success in 453ms DTS dist/lib-imports-bar-using-main.d.ts 60.00 B ```pnpm run build-bar-dts-resolve
❌Importing from “support-lib” with the subpath “./bar-that-imports-foo”, and building the library using tsup with
dts: { resolve: true }
:failed
``` ➜ lib-to-be-built git:(main) pnpm run build-bar-dts-resolve > @tsup-reproduction-dts-resolve-pnpm-workspace/lib-to-be-built@1.0.0 build-bar-dts-resolve /private/tmp/test/packages/lib-to-be-built > tsup --config tsup.bar-dts-resolve.config.ts CLI Building entry: lib-imports-bar.ts CLI Using tsconfig: tsconfig.json CLI tsup v7.2.0 CLI Using tsup config: /private/tmp/test/packages/lib-to-be-built/tsup.bar-dts-resolve.config.ts CLI Target: es2020 CLI Cleaning output folder ESM Build start ESM dist/lib-imports-bar.js 98.00 B ESM ⚡️ Build success in 16ms DTS Build start Error parsing: /private/tmp/test/packages/support-lib/foo.ts:1:7 Error: error occured in dts build at Worker.Upvote & Fund