.
βββ package.json
βββ src
β βββ index.ts
βββ tsconfig.json
βββ tt
βββ a
β βββ aa.ts
βββ b
βββ bb.ts
my tsconfig.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"isolatedModules": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": false,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"strict": true,
"incremental": false,
"target": "es2021",
"baseUrl": ".",
"lib": ["es2021"],
"outDir": "./dist",
"rootDir": ".",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"rootDirs": [
"src",
"tt/b",
"tt/a"
]
},
"include": ["src", "__tests__/**/*.ts", "tt"],
"exclude": ["node_modules"]
}
// src/index.ts
import { b } from "./bb";
console.log(b);
// tt/a/aa.ts
export const a = 1;
// tt/b/bb.ts
import { a } from "./aa";
console.log(a);
export const b = 2;
while running tsup --watch
it errors
β [ERROR] Could not resolve "./bb"
src/index.ts:1:18:
1 β import { b } from "./bb";
β΅ ~~~~~~
ESM Build failed
Error: Build failed with 1 error:
src/index.ts:1:18: ERROR: Could not resolve "./bb"
at failureErrorWithLog (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1575:15)
at /Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1033:28
at runOnEndCallbacks (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1447:61)
at buildResponseToResult (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1031:7)
at /Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1143:14
at responseCallbacks.<computed> (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:680:9)
at handleIncomingPacket (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:735:9)
at Socket.readFromStdout (/Users/silentlee/Desktop/eslint-config-bnc/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:656:7)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:315:12)
β [ERROR] Could not resolve "./bb"
src/index.ts:1:18:
1 β import { b } from "./bb";
β΅ ~~~~~~
CJS Build failed
with ./node_modules/.bin/tsc --traceResolution | grep -A 41 "======== Resolving module './bb'" --color=auto
======== Resolving module './bb' from '/Users/silentlee/Desktop/eslint-config-bnc/src/index.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'rootDirs' option is set, using it to resolve relative module name './bb'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/src/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/src/bb' - 'true'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/src/bb' - 'false'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/src/bb' - 'false'.
Longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/src/bb' is '/Users/silentlee/Desktop/eslint-config-bnc/src/'.
Loading 'bb' from the root dir '/Users/silentlee/Desktop/eslint-config-bnc/src/', candidate location '/Users/silentlee/Desktop/eslint-config-bnc/src/bb'.
Loading module as file / folder, candidate module location '/Users/silentlee/Desktop/eslint-config-bnc/src/bb', target file type 'TypeScript'.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/bb.ts' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/bb.tsx' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/bb.d.ts' does not exist.
Directory '/Users/silentlee/Desktop/eslint-config-bnc/src/bb' does not exist, skipping all lookups in it.
Trying other entries in 'rootDirs'.
Loading 'bb' from the root dir '/Users/silentlee/Desktop/eslint-config-bnc/tt/b', candidate location '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/bb'.
Loading module as file / folder, candidate module location '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/bb', target file type 'TypeScript'.
File '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/bb.ts' exist - use it as a name resolution result.
======== Module name './bb' was successfully resolved to '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/bb.ts'. ========
======== Resolving module './aa' from '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/bb.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'rootDirs' option is set, using it to resolve relative module name './aa'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/src/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa' - 'false'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa' - 'true'.
Checking if '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/' is the longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa' - 'false'.
Longest matching prefix for '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa' is '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/'.
Loading 'aa' from the root dir '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/', candidate location '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa'.
Loading module as file / folder, candidate module location '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa', target file type 'TypeScript'.
File '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa.ts' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa.tsx' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa.d.ts' does not exist.
Directory '/Users/silentlee/Desktop/eslint-config-bnc/tt/b/aa' does not exist, skipping all lookups in it.
Trying other entries in 'rootDirs'.
Loading 'aa' from the root dir '/Users/silentlee/Desktop/eslint-config-bnc/src', candidate location '/Users/silentlee/Desktop/eslint-config-bnc/src/aa'.
Loading module as file / folder, candidate module location '/Users/silentlee/Desktop/eslint-config-bnc/src/aa', target file type 'TypeScript'.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/aa.ts' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/aa.tsx' does not exist.
File '/Users/silentlee/Desktop/eslint-config-bnc/src/aa.d.ts' does not exist.
Directory '/Users/silentlee/Desktop/eslint-config-bnc/src/aa' does not exist, skipping all lookups in it.
Loading 'aa' from the root dir '/Users/silentlee/Desktop/eslint-config-bnc/tt/a', candidate location '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/aa'.
Loading module as file / folder, candidate module location '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/aa', target file type 'TypeScript'.
File '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/aa.ts' exist - use it as a name resolution result.
======== Module name './aa' was successfully resolved to '/Users/silentlee/Desktop/eslint-config-bnc/tt/a/aa.ts'. ========
and it can build succeed with tsc
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