Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tailwind + publishable libs build error #22043

Closed
2 of 4 tasks
PatoDeVille opened this issue Feb 28, 2024 · 5 comments
Closed
2 of 4 tasks

tailwind + publishable libs build error #22043

PatoDeVille opened this issue Feb 28, 2024 · 5 comments
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@PatoDeVille
Copy link

Current Behavior

I am having a problem with a library in my project, which is consuming other "sister" libraries in the monorepo.

This is the "default" build step and it has no issues building or what so ever.

"build": {
     "executor": "@nx/angular:package",
     "outputs": ["{workspaceRoot}/dist/{projectRoot}"],
     "options": {
       "project": "libs/containers/ng-package.json"
     },
     "configurations": {
       "production": {
         "tsConfig": "libs/containers/tsconfig.lib.prod.json"
       },
       "development": {
         "tsConfig": "libs/containers/tsconfig.lib.json"
       }
     },
     "defaultConfiguration": "production"
   }

But if i add tailwind and the configuration suggested in the NX + angular + tailwind recipe

{
  "name": "containers",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/containers/src",
  "prefix": "uve-containers",
  "tags": [
    "domain:containers",
    "type:containers",
    "uve:lib"
  ],
  "projectType": "library",
  "targets": {
    "build-angular": {
      "executor": "@nx/angular:package",
      "outputs": [
        "{workspaceRoot}/dist/{projectRoot}"
      ],
      "options": {
        "project": "libs/containers/ng-package.json",
        "tailwindConfig": "libs/containers/tailwind.config.js"
      },
      "configurations": {
        "production": {
          "tsConfig": "libs/containers/tsconfig.lib.prod.json"
        },
        "development": {
          "tsConfig": "libs/containers/tsconfig.lib.json"
        }
      },
      "defaultConfiguration": "production"
    },
    "build-lib": {
      "executor": "nx:run-commands",
      "outputs": [
        "{workspaceRoot}/dist/libs/containers"
      ],
      "configurations": {
        "production": {
          "commands": [
            "nx run containers:build-angular:production",
            "nx run containers:build-themes:production"
          ]
        },
        "development": {
          "commands": [
            "nx run containers:build-angular:development",
            "nx run containers:build-themes:development"
          ]
        }
      },
      "defaultConfiguration": "production"
    },
    "build-themes": {
      "executor": "nx:run-commands",
      "outputs": [
        "{workspaceRoot}/dist/libs/containers/themes"
      ],
      "configurations": {
        "production": {
          "commands": [
            "tailwindcss -c libs/containers/tailwind.config.js -i ./libs/containers/src/styles/styles.css -o ./dist/libs/containers/themes/styles.css -m"
          ]
        },
        "development": {
          "commands": [
            "tailwindcss -c libs/containers/tailwind.config.js -i ./libs/containers/src/styles/styles.css -o ./dist/libs/containers/themes/styles.css"
          ]
        }
      },
      "defaultConfiguration": "production"
    },
    "new-build": {
      "dependsOn": [
        "build"
      ],
      "command": "echo dummy build",
      "options": {
        "outputPath": "dist/libs/containers",
        "tsConfig": "libs/containers/tsconfig.lib.json"
      }
    },
    "build": {
      "executor": "nx:run-commands",
      "outputs": [
        "{workspaceRoot}/dist/libs/containers"
      ],
      "configurations": {
        "production": {
          "commands": [
            "rm -rf dist/libs/containers",
            "nx run containers:build-lib:production"
          ]
        },
        "development": {
          "commands": [
            "rm -rf dist/libs/containers",
            "nx run containers:build-lib:development"
          ]
        }
      },
      "defaultConfiguration": "production"
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": [
        "{workspaceRoot}/coverage/libs/containers"
      ],
      "options": {
        "jestConfig": "libs/containers/jest.config.ts",
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    },
    "lint": {
      "executor": "@nx/linter:eslint",
      "outputs": [
        "{options.outputFile}"
      ],
      "options": {
        "lintFilePatterns": [
          "libs/containers/**/*.ts",
          "libs/containers/**/*.html",
          "libs/containers/package.json"
        ]
      }
    }
  }
}

I get errors regarding TS6059 and TS5055 that "file/from/another/lib" is not exported in rootDir

any ideas what could it be?
im using NX 16

Expected Behavior

build normally regardless if is using another library from the project or not

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node   : 20.9.0
   OS     : darwin-arm64
   npm    : 10.1.0
   
   nx                 : 16.9.1
   @nx/js             : 16.9.1
   @nx/jest           : 16.9.1
   @nx/linter         : 16.9.1
   @nx/workspace      : 16.9.1
   @nx/angular        : 16.9.1
   @nx/cypress        : 16.9.1
   @nx/devkit         : 16.9.1
   @nx/eslint-plugin  : 16.9.1
   @nx/storybook      : 16.9.1
   @nrwl/tao          : 16.9.1
   @nx/web            : 16.9.1
   @nx/webpack        : 16.9.1
   nx-cloud           : 16.4.0
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @compodoc/compodoc       : 1.1.23
   @ngneat/transloco        : 4.2.7
   @storybook/angular       : 7.4.5
   angular-auth-oidc-client : 15.0.4

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

if i am using a library with tailwind and the same configuration but said library doesnt import anything from the rest... it builds smoothly

@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Feb 29, 2024
@leosvelperez
Copy link
Member

Thanks for reporting this!

The issue happens because of a constraint regarding build target names (https://nx.dev/recipes/angular/setup-incremental-builds-angular#build-target-name). What's happening is that the target with an executor that supports incremental builds in your containers library now has a different name (build-angular) while its dependencies (e.g. the project that contains the file/from/another/lib path) probably still have build. The way incremental builds currently work, the target names should be the same.

We are trying out (and plan to enable it by default) a new way of calculating the target dependencies for incremental builds that should not be constrained by this. Could you try running your command with the NX_BUILDABLE_LIBRARIES_TASK_GRAPH=true env var and let me know if it works?

@PatoDeVille
Copy link
Author

thanks for your response @leosvelperez but no luck :(

@leosvelperez
Copy link
Member

hey @PatoDeVille! Apologies for the delay in getting back to you.

One thing I missed last time is that we need to make sure the task graph has the correct dependencies so Nx can properly figure out the buildable libs dependencies. To do so, please update your targetDefaults in nx.json and add the following:

{
  ...
  "targetDefaults": {
    ...
    "build-angular": {
      "dependsOn": ["^build"]
    },
  },
  ...
}

With that in place, you can build your library (or app) setting the env var I mentioned in my last comment:

NX_BUILDABLE_LIBRARIES_TASK_GRAPH=true nx build my-lib
NX_BUILDABLE_LIBRARIES_TASK_GRAPH=true nx build my-app

The important bit is that any target using one of the Nx executors that supports incremental builds (e.g. @nx/angular:package) must specify the tasks it depends on. In this case, the build-angular task uses the @nx/angular:package executor, and it depends on projects that use the build task with a similar executor. That's why we need to set up that dependency in the build pipeline. Additionally, the NX_BUILDABLE_LIBRARIES_TASK_GRAPH env var enables a new way of calculating those dependencies relying on the task graph and not just on the target name (previous behavior).

Please let me know if you still have any issues after making the adjustments above.

@leosvelperez
Copy link
Member

I'm closing this since a solution was provided in #22043 (comment) (I tested it in a repo with a similar setup as this issue's description).

@PatoDeVille, if you still have any issues after following the instructions on that comment, please leave a message, and I'll take a look.

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

2 participants