Hi!
I encountered the following strange error when trying to set up a build step with tsup
for a library in a monorepo:
$ pnpm nx build my-library # <-- original command run in terminal
β 1/1 dependent project tasks succeeded [1 read from cache]
Hint: you can run the command with --verbose to see the full dependent project outputs
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
> nx run my-library:build
> @my-monorepo/[email protected] build /my-monorepo/libs/my-library
> tsup
β² [WARNING] "tsconfig.json" does not affect esbuild's own target setting [tsconfig.json]
../../tsconfig.base.json:11:8:
11 β "target": "es2015",
β΅ ~~~~~~~~
This is because esbuild supports reading from multiple "tsconfig.json" files within a single build, and using different language targets for different files in the same build wouldn't be correct. If you want to set esbuild's language target, you should use esbuild's own global "target" setting such as with "target: 'es2015'".
β² [WARNING] "tsconfig.json" does not affect esbuild's own target setting [tsconfig.json]
../../tsconfig.base.json:11:8:
11 β "target": "es2015",
β΅ ~~~~~~~~
This is because esbuild supports reading from multiple "tsconfig.json" files within a single build, and using different language targets for different files in the same build wouldn't be correct. If you want to set esbuild's language target, you should use esbuild's own global "target" setting such as with "target: 'es2015'".
CLI Building entry: src/index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v7.0.0
CLI Using tsup config: /my-monorepo/libs/my-library/tsup.config.ts
CLI Target: es2015
CLI Cleaning output folder
ESM Build start
ESM ../../dist/libs/my-library/index.js 13.21 KB
ESM β‘οΈ Build success in 111ms
onSuccess:
- Copied README.md and ../../LICENSE to out directory.
- Merged package.json and ../../package.json and wrote to out directory.
- Done.
DTS Build start
src/index.ts(1,15): error TS6059: File '/my-monorepo/libs/my-other-library/src/index.ts' is not under 'rootDir' '.'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Imported via "@my-monorepo/my-other-library" from file '/my-monorepo/libs/my-library/src/index.ts'
Error: error occured in dts build
at Worker.<anonymous> (/my-monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/tsup/dist/index.js:2297:26)
at Worker.emit (node:events:513:28)
at MessagePort.<anonymous> (node:internal/worker:243:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
RollupError: Failed to compile. Check the logs above.
at error (/my-monorepo/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/shared/rollup.js:279:30)
at Object.error (/my-monorepo/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/shared/rollup.js:24825:20)
at Object.error (/my-monorepo/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/shared/rollup.js:24019:42)
at generateDtsFromTs (/my-monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/tsup/dist/rollup.js:7498:22)
at /my-monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/tsup/dist/rollup.js:7505:59
at _nullishCoalesce (/my-monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/tsup/dist/rollup.js:1:198)
at Object.transform (/my-monorepo/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/tsup/dist/rollup.js:7505:18)
at /my-monorepo/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/shared/rollup.js:25024:40
βELIFECYCLEβ Command failed with exit code 1.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
> NX Ran target build for project my-library and 1 task(s) they depend on (4s)
β 1/2 failed
β 1/2 succeeded [1 read from cache]
It's a Nx monorepo and my-library
depends on my-other-library
.
Directory structure looks like following:
my-monorepo/
ββ libs/
β ββ my-library/
β β ββ tsconfig.json
β β ββ tsup.config.ts
β ββ my-other-library/
β β ββ tsconfig.json
ββ tsconfig.base.json
In tsconfig.base.json
:
{
"compilerOptions": {
"rootDir": ".",
"paths": {
"@my-monorepo/my-library": [
"libs/my-library/src/index.ts"
],
"@my-monorepo/my-other-library": [
"libs/my-other-library/src/index.ts"
],
}
}
}
In libs/my-library/tsconfig.json
:
{
"extends": "../../tsconfig.base.json"
}
My theory is that the issue has to do with tsup
(or rollup-plugin-dts
, which it uses internally for generating the declaration files) viewing "rootDir": "."
as pointing to /my-monorepo/libs/my-library/
(the root directory of the library), when in fact "rootDir": "."
is meant to be viewed as pointing to /my-monorepo/
(the root directory of the monorepo) as it's defined in tsconfig.base.json
which resides in the root directory of the monorepo, so relative paths within that file should be resolved relative to the location of the file.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too