Nx: Warning on running nest api

Created on 14 Oct 2020  路  5Comments  路  Source: nrwl/nx

Current Behavior

It shows an warning when I run nx serve api in a recently created workspace with nest and angular.

WARNING in ./apps/api/src/app/app.controller.ts 18:56-63
"export 'Message' was not found in '@test/api-interfaces'

WARNING in ./apps/api/src/app/app.controller.ts 18:83-90
"export 'Message' was not found in '@test/api-interfaces'

Expected Behavior

I expected it to work without warnings when I create it.

Steps to Reproduce

You should run:
npx create-nx-workspace test

Select the options:

angular-nest      [a workspace with a full stack application (Angular + Nest)]
Application name                    test
Default stylesheet format           SASS(.scss)  [ http://sass-lang.com   ]
Default linter                      TSLint [ Used by Angular CLI ]

Go to the directory
cd test

Use:
nx serve api

Environment

File contents:
/libs/api-interfaces/src/index.ts
export * from './lib/api-interfaces';

/libs/api-interfaces/src/lib/api-interfaces.ts

export interface Message {
  message: string;
}

>  NX  Report complete - copy this into the issue template

  nx : Not Found
  @nrwl/angular : 10.3.0
  @nrwl/cli : 10.3.0
  @nrwl/cypress : 10.3.0
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 10.3.0
  @nrwl/linter : 10.3.0
  @nrwl/nest : 10.3.0
  @nrwl/next : Not Found
  @nrwl/node : 10.3.0
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.3.0
  @nrwl/web : Not Found
  @nrwl/workspace : 10.3.0
  typescript : 4.0.3

It happened with versions 6.14.7 and 10.3.0.

node bug

Most helpful comment

@inglkruiz Thanks for your comment. It led to the solution.

I mean that instead of import {MyCustom} from "...";, using import type {MyCustom} from "..."; solves the problem.

All 5 comments

It looks like it's related to the automatic creation of tsconfig.generated.json in tmp\apps\api directory because that contains the repeated definition of @xxx/api-interfaces path. As I know, it's necessary to restart, for example, VS Code to make such a new path usable. The original definition of @xxx/api-interfaces already exists in tsconfig.base.json located in the project root.

{
  "compilerOptions": {
    "paths": {
      "@xxx/api-interfaces": [
        "libs/api-interfaces/src/index.ts"
      ]
    }
  },
  "extends": "..\\..\\..\\apps\\api\\tsconfig.app.json"
}

Anything new? Can anybody explain what is responsible for creating the temporary tsconfig.generated.json config and its sense? It's generally very confusing behavior when you use shared libs (each import from such libs means a new additional warning), it's about hundreds of such warnings, and it takes a lot of space and time to print.

Just for the record. In a big monorepo at my job this started to happen after migrating to the latest version. In a small project that I scaffolded 2 weeks ago, it started to happen as soon as I started to export TS types and interfaces. Feel free to check this GH action https://github.com/inglkruiz/alethio-demo/runs/1368698054?check_suite_focus=true#step:10:1

@Guilherhast after reading this article and tried the solution proposed the warnings were gone > https://medium.com/javascript-in-plain-english/leveraging-type-only-imports-and-exports-with-typescript-3-8-5c1be8bd17fb also you might want to check this https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
Found solutions here https://github.com/webpack/webpack/issues/7378

@inglkruiz Thanks for your comment. It led to the solution.

I mean that instead of import {MyCustom} from "...";, using import type {MyCustom} from "..."; solves the problem.

Was this page helpful?
0 / 5 - 0 ratings