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.

The file is not under 'rootDir' when building

See original GitHub issue

Current Behavior

When building, an error gets thrown:

rpt2: options error TS6059: File 'path-to-project/libs/ui/utils/setup-tests-after-env.ts' is not under 'rootDir' 'path-to-project/libs/ui/src'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Root file specified for compilation
rpt2: options error TS6059: File 'path-to-project/libs/ui/utils/ui-test-utils.tsx' is not under 'rootDir' 'path-to-project/libs/ui/src'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Root file specified for compilation

This is my setup.

path-to-project/libs/ui/tsconfig.json
{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "jsx": "react-jsx",
    "types": ["node", "jest"]
  },
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.lib.json"
    },
    {
      "path": "./tsconfig.spec.json"
    },
    {
      "path": "./.storybook/tsconfig.json"
    }
  ]
}
path-to-project/libs/ui/tsconfig.spec.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs"
  },
  "include": [
    "**/*.spec.ts",
    "**/*.spec.tsx",
    "**/*.spec.js",
    "**/*.spec.jsx",
    "**/*.d.ts",
    "./utils/setup-tests-after-env.ts"
  ]
}
path-to-project/tsconfig.base.json
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "strict": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "allowJs": false,
    "noImplicitAny": true,
    "allowSyntheticDefaultImports": true,
    "paths": {
       ...
    },
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  },
  "exclude": ["node_modules", "tmp", "dist"]
}

path-to-project/libs/ui/utils/setup-tests-after-env.ts

import '@testing-library/jest-dom';

Based on other suggestions, I am not sure how to check if some libraries are publishable/buildable. I believe I have not used any of those two options when building these apps/libraries.

Expected Behavior

The error shouldn’t be happening.

Environment

Node : 14.15.4 OS : win32 x64 yarn : 2.4.2

nx : 11.1.1 @nrwl/angular : Not Found @nrwl/cli : 12.1.1 @nrwl/cypress : 12.1.1 @nrwl/devkit : 12.1.1 @nrwl/eslint-plugin-nx : 12.1.1 @nrwl/express : Not Found @nrwl/jest : 12.1.1 @nrwl/linter : 12.1.1 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : 12.1.1 @nrwl/schematics : 8.12.11 @nrwl/tao : 12.1.1 @nrwl/web : 12.1.1 @nrwl/workspace : 12.1.1 @nrwl/storybook : 12.1.1 @nrwl/gatsby : Not Found typescript : 4.3.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

35reactions
luukvhoudtcommented, Oct 24, 2021

I also encountered this problem while building a library.

The fix for me was updating the package.json. Apparently the package name has to match the tsconfig path name / the import path (nx generate @nrwl/node:library --importPath)

20reactions
datumgeekcommented, Dec 20, 2021

i also encountered this problem…

it was killing me… i couldn’t figure out why nx didn’t build right… it was giving me tons of errors about one of my referenced project @scope1/lib2 and all of its .ts files being outside the project that referenced it… i also noticed that the dep-graph had @scope1/lib2 but there was no dependency arrow from the referencing library…

i found this fix: rm -rf node_modules/.cache

i’m guessing nx had something in the cache that was wrong… after deleting, the dep-graph finally showed the link properly and the build started working

Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS6059: File is not under 'rootDir' .. 'rootDir' is expected ...
One fix is to just remove "rootDir": "src" from compiler options, so it gets set automatically. Caution: rootDir will then consider both ...
Read more >
If not all sources are under rootDir, you only get an ... - GitHub
the rootDir is used to build the output folder structure. all files have to be under rootDir for the compiler to know where...
Read more >
TSConfig Option: rootDir - TypeScript
When TypeScript compiles files, it keeps the same directory structure in the ... for rootDir is the longest common path of all non-declaration...
Read more >
Angular,monorepo,multiple libs and rootDir issue | by Arun Malik
On running “ng build lib1” All we got is this… error TS6059: File '/Users/admin/Desktop/App/libs/lib2/src/util.ts' is not under 'rootDir' ...
Read more >
nrwl-nx/community - Gitter
'test-lib/libs/my-lib/src/index.ts' is not under 'rootDir' 'test-lib\libs\another\src'. 'rootDir' is expected to contain all source files. for example.
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