I use yarn workspaces and have the following packages:
- packages/x-cli
- packages/x-core
I want to be able to import symbols from x-core subdirectories, the same way you would do import map from 'lodash/map'
, example:
import { fn } from '@mycompany/x-core/test';
But I get the following error:
tsc -b packages/x-core packages/x-cli
packages/x-cli/src/main.ts:1:20 - error TS2307: Cannot find module '@mycompany/x-core/test'.
1 import { fn } from "@mycompany/x-core/test";
~~~~~~~~~~~~~~~~~~~~~~~~
error Command failed with exit code 1.
This works though, if it is exported in the root of the library:
import { otherFn } from '@mycompany/x-core';
I made a small project on Github to show exactly my setup, based on lerna-yarn-workspaces-example: https://github.com/julienfouilhe/example-subdirectory-workspace-typescript-import
Is there a way to do this, I can't find anything that works. I don't know much about module resolution so I can't pinpoint the problem exactly!