Can't import files from one library into another library (bypassing index.ts)
See original GitHub issueCurrent Behavior
I have a process on our back end that auto generates interfaces, enums and services that are necessary to call our back end. All of these get generated into three directories: interfaces, enums and services. I have put these directories into buildable library that is structured like this: /libs/api/src/{interfaces,enums,services} In each directory are the appropriate TS files.
In my tsconfig.base.json file, I have added the following path entries:
"@skycourt/api/enums/*": ["libs/api/src/enums/*"],
"@skycourt/api/interfaces/*": ["libs/api/src/interfaces/*"],
"@skycourt/api/services/*": ["libs/api/src/services/*"],
In the second library, called helpers, I import a couple of the enums and interfaces like this:
import { ActivityType } from '@skycourt/api/enums/ActivityType';
VSCode happily recognizes these paths. Lint happily recognizes these paths and I am able to run the jest tests in the second library that uses these paths.
However, when I try to build the helpers library, I get these errors:
Compiling TypeScript files for project "common-helpers"...
libs/common/helpers/src/lib/ActivityIcon.ts:1:30 - error TS2307: Cannot find module '@skycourt/api/enums/ActivityType' or its corresponding type declarations.
1 import { ActivityType } from '@skycourt/api/enums/ActivityType';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I know that Nx understands the dependency betwen helpers and api because when I display the graph, there is an arrow from helpers to api.
Expected Behavior
I expected the import to be resolved properly while building.
Steps to Reproduce
I have created a minimal repo using Nx 13.9.7 that illustrates the issue. I am using 13.9.7 because my main project is a Vue app and Nx-plus/vue can’t seem to be used with anything newer than 13.9.7.
If you clone this repo: https://github.com/gregveres/nx-import-bug
and then execute nx build helpers
you willl see this error:
Compiling TypeScript files for project "helpers"...
libs/helpers/src/lib/helpers.ts:1:30 - error TS2307: Cannot find module '@myorg/api/enums/ActivityType' or its corresponding type declarations.
1 import { ActivityType } from '@myorg/api/enums/ActivityType'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
when it really should compile.
Environment
04-30 13:11:32 17> nx report
> NX Report complete - copy this into the issue template
Node : 16.13.2
OS : win32 x64
yarn : 1.22.17
nx : 13.9.7
@nrwl/angular : Not Found
@nrwl/cypress : 13.9.7
@nrwl/detox : Not Found
@nrwl/devkit : 13.9.7
@nrwl/eslint-plugin-nx : 13.9.7
@nrwl/express : Not Found
@nrwl/jest : 13.9.7
@nrwl/js : 13.9.7
@nrwl/linter : 13.9.7
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/workspace : 13.9.7
typescript : 4.5.5
rxjs : 6.6.7
---------------------------------------
Community plugins:
Issue Analytics
- State:
- Created a year ago
- Comments:8
The PR that was merged is a step in the right direction but as far as I can tell doesn’t allow bypassing the index.ts. This should be reopened
For others running into this issue. I ran into this error in one of my applications and the issue ended up being an issue with my application
tsconfig.app.json
. I had an empty “paths”: {}` object in my config overriding the root ts config where the library paths are set up. Broken config, removing paths fix this issue for me