question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import files from one library into another library (bypassing index.ts)

See original GitHub issue

Current 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:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
mcarrierecommented, Oct 11, 2022

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

1reaction
mbrimmer83commented, Dec 11, 2022

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

"compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["node", "express"],
    "paths": {} // Remove this line or be sure to merge the root level to resolve libs
    "composite": true
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

0 - Stack Overflow
I'm new to working on OpenSource Projects and I'm currently exploring the area. I found this repository and I'm trying to solve an...
Read more >
Angular compiler options
ts file supplied in the files field is assumed to be the library index. If more than one .ts file is specified, libraryIndex...
Read more >
Import photos from another library in Photos on Mac
Choose File > Import. In the Import window, select the Photos library that contains the photos and videos that you want to import,...
Read more >
How to Create and Publish a React Component Library
import React from "react"; export interface ButtonProps { label: ... The entrypoint for our library (input) is the index.ts file in the src ......
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
In [1]: import pandas as pd In [2]: from io import StringIO In [3]: data ... pandas cannot natively represent a column or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found