Nested Module Resolution?
See original GitHub issueI’m trying to figure out how to get nested module resolution working with this project.
What I mean is modifying the structure to a more real-world example with multiple nested modules, in a domain driven architecture where all our exports are in a domain and referenced by e.g. import { sleep } from '@quramy/x-core/messages/core'
Structure:
- x-cli
-- src
--- main.ts
- x-core
-- src
--- messages
---- core
----- sleep
------ sleep.ts
------ sleep-and-snore.ts
------ index.ts
----- wake
------ wake.ts
------ wake-and-eat.ts
------ index.ts (exports wake and wake-and-eat)
I have modified /tsconfig.json
: and then updated main.ts:
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./packages",
"paths": {
"@quramy/x-core/messages/*": ["./x-core/src/messages/*"],
"@quramy/*": ["./*/src"]
}
}
}
// main.ts (this works fine in the IDE, just doesn't build...)
import { sleep, sleepAndSnore } from '@quramy/x-core/messages/core'
export function cli() {
sleep();
sleepAndSnore()
return Promise.resolve(true);
}
cli()
yarn prepare
then gives me this error:
src/main.ts(1,38): error TS2307: Cannot find module ‘@quramy/x-core/messages/core’.
If I add the paths/baseUrl to the tsconfig.build.json, it will build, but it doesn’t run because it can’t find the module.
I also get the "source files not under the same rootDir message if I have that compilerOption set under this case: TS6059: File '/home/bthompson/source/lerna-yarn-workspaces-example/packages/x-core/src/messages/core/index.ts' is not under 'rootDir' '/home/bthompson/source/lerna-yarn-workspaces-example/packages/x-cli/src'. 'rootDir' is expected to contain all source files.
Any help would be greatly appreciated!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:7
I solved this by using module-alias package.
@dgreene1 Still working on it, should be out soon.