Nx publishable library: 'rootDir' is expected to contain all source files after running build

100 views Asked by At

I created a publishable Nx library that has a project.json like this (only build target):

{
  "name": "@pace-io/myLib",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/myLib/src",
  "projectType": "library",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/rollup:rollup",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/myLib",
        "tsConfig": "libs/myLib/tsconfig.lib.json",
        "project": "libs/myLib/package.json",
        "entryFile": "libs/myLib/src/index.ts",
        "external": ["react", "react-dom", "react/jsx-runtime"],
        "rollupConfig": "@nx/react/plugins/bundle-rollup",
        "compiler": "babel",
        "assets": [
          {
            "glob": "libs/myLib/README.md",
            "input": ".",
            "output": "."
          }
        ],
        "stylePreprocessorOptions": {
          "includePaths": ["libs/styles/src"]
        }
      }
    }
  }
}

Then I created a library for hooks that has a project.json like this:

{
  "name": "hooks",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/hooks/src",
  "projectType": "library",
  "tags": [],
  "targets": {
    "lint": {
      "executor": "@nx/eslint:lint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["libs/hooks/**/*.{ts,tsx,js,jsx}"]
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "libs/hooks/jest.config.ts"
      }
    }
  }
}

My import paths within the tsconfig.json look like this:

  "@org/libs/hooks": ["libs/hooks/src/index.ts"],
  "@org/myLib": ["libs/my-lib/src/index.ts"],

Within the publishable library "myLib" I import a hook like this:

import { useAuthService } from '@org/libs/hooks';

Currently after running a build I get this error:

Error during bundle: Error: libs/myLib/src/lib/myLib.tsx:13:34 - error TS6059: File '/Users/me/Documents/repositories/demo-project/libs/hooks/src/index.ts' is not under 'rootDir' '/Users/me/Documents/repositories/demo-project/libs/my-lib'. 'rootDir' is expected to contain all source files.

How can I fix this issue? I already checked some approaches provided in the Nx repository but none of them worked. Hope someone can help me with this..

0

There are 0 answers