AlexPshul / nxazure

MIT License
16 stars 7 forks source link

tsconfig file does not include "references" #37

Open vladkasianenko opened 1 month ago

vladkasianenko commented 1 month ago

When creating a function, the output of tsconfig.json does not include extends and references properties. So if I have a shared library, I need to manually register path inside tsconfig.build.json, which is not convenient.

Compare to the Angular and Lib: Listing of tsconfig.base.json which is in the root:

{
 "compilerOptions": {
   "paths": {
      "@org-name/myLib": ["libs/myLib/src/index.ts"]
    },
    // other definitions
 }
}

Angular's tsconfig.json:

{
  "extends": "../../tsconfig.base.json",
  "references": [
    { "path": "./tsconfig.editor.json" },
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.spec.json" },
  ],
  // other definitions
}

Angular's tsconfig.app.json:

{
  "extends": "./tsconfig.json",
  // other definitions
}

So in any file of Angular app, I can import something from the myLib using import { myFunc } from '@org-name/myLib'; I can't do the same with Azure Functions. The _registerPaths.ts seems not working for me.

AlexPshul commented 4 weeks ago

Thanks for reporting this, @vladkasianenko. Can you please give me the minimum reproduction scenario? Is it an android app + an azure function? Which NX version are you using?

This will help me greatly to make sure that different scenarios are working properly.

vladkasianenko commented 3 weeks ago

It is Angular + Shared Lib + Azure Function.

Node           : 22.9.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.8.3

nx (global)        : 19.8.3
nx                 : 19.6.3
@nx/js             : 19.6.3
@nx/jest           : 19.6.3
@nx/linter         : 19.8.3
@nx/eslint         : 19.8.3
@nx/workspace      : 19.6.3
@nrwl/workspace    : 19.8.4
@nx/angular        : 19.6.3
@nx/cypress        : 19.6.3
@nx/devkit         : 19.6.3
@nx/esbuild        : 19.6.3
@nx/eslint-plugin  : 19.8.3
@nx/node           : 19.6.3
@nrwl/tao          : 19.6.3
@nx/web            : 19.6.3
@nx/webpack        : 19.6.3
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/cypress/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
@nxazure/func : 1.1.6
---------------------------------------
vladkasianenko commented 2 weeks ago

Another issue with these paths is that:

  1. Run the npx nx build myfunc - that procudes the following dist folder
    apps
    libs
    tsconfig.base.json
  2. Run the node apps\func\src\functions\function.js This gives the error: Cannot find module '@org-name/myLib'
AlexPshul commented 2 weeks ago

@vladkasianenko Could you please share your shared lib project.json file?

Another issue with these paths is that:

  1. Run the npx nx build myfunc - that procudes the following dist folder
    apps
    libs
    tsconfig.base.json
  2. Run the node apps\func\src\functions\function.js This gives the error: Cannot find module '@org-name/myLib'

Could you try to use the other executor to run the function app? Try nx start myfunc. This executor has other steps that are necessary to run the function app which will use the imports and everything.

vladkasianenko commented 1 week ago

project.json

{
  "name": "myLib",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/myLib/src",
  "projectType": "library",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/js:tsc",
      "outputs": [
        "{options.outputPath}"
      ],
      "options": {
        "outputPath": "dist/libs/myLib",
        "tsConfig": "libs/myLib/tsconfig.lib.json",
        "packageJson": "libs/myLib/package.json",
        "main": "libs/myLib/src/index.ts",
        "assets": [
          "libs/myLib/*.md"
        ]
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": [
        "{workspaceRoot}/coverage/{projectRoot}"
      ]
    }
  }
}
AlexPshul commented 4 days ago

Unfortunately, I couldn't reproduce the issue on my end. All works for me as expected. Just to make sure, do you start your functions with the start command? nx start myfunc?

If you can create a repo with just 3 projects that can reproduce the issue, I'll be glad to have a look at it.