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.

File is not under 'rootDir' 'packages'. 'rootDir' is expected to contain all source files in npm preset

See original GitHub issue

Current Behavior

Got an error when I run yarn nx run foo:build

Compiling TypeScript files for project "foo"...
packages/core/src/index.ts:1:15 - error TS6059: File '/Users/wizardnet972/repo/nx-npm-preset/packages/core/src/lib/core.ts' is not under 'rootDir' 'packages/foo'. 'rootDir' is expected to contain all source files.

1 export * from './lib/core';
                ~~~~~~~~~~~~
packages/foo/src/lib/foo.ts:1:22 - error TS6059: File '/Users/wizardnet972/repo/nx-npm-preset/packages/core/src/index.ts' is not under 'rootDir' 'packages/foo'. 'rootDir' is expected to contain all source files.

1 import { core } from '@nx-npm-preset/core';
                       ~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

nx should build foo and core

Steps to Reproduce

Clone: git clone https://github.com/wizardnet972/nx-npm-preset.git Run:

yarn install
yarn nx run foo:build

See the error in Current Behavior

– OR – Run those commands:

npx create-nx-workspace nx-npm-preset
✔ What to create in the new workspace · npm
✔ Use Nx Cloud? (It's free and doesn't require registration.) · No

yarn add @nrwl/js @nrwl/node -W

yarn nx g @nrwl/js:lib --name core --buildable
yarn nx g @nrwl/js:lib --name foo --buildable

Replace the content of /packages/foo/src/lib/foo.ts with: (https://github.com/wizardnet972/nx-npm-preset/blob/main/packages/foo/src/lib/foo.ts)

import { core } from '@nx-npm-preset/core';

export function foo(): string {
  core();
  return 'foo';
}

Run:

yarn nx run foo:build

See the error in Current Behavior

Failure Logs

See the error in Current Behavior

Environment


 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin arm64
   yarn : 1.22.19

   nx : 14.3.5
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.3.5
   @nrwl/eslint-plugin-nx : 14.3.5
   @nrwl/express : Not Found
   @nrwl/jest : 14.3.5
   @nrwl/js : 14.3.5
   @nrwl/linter : 14.3.5
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.3.5
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 14.3.5
   typescript : 4.7.3
   ---------------------------------------
   Community plugins:

✨  Done in 0.83s.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:27
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
codewaseemcommented, Jun 20, 2022

Facing same issue.

4reactions
itsrennymancommented, Jun 22, 2022

Facing same issue too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS6059: File is not under 'rootDir' .. 'rootDir' is expected ...
rootDir is set to a root folder, that contains all your source files. If not specified, TS will automatically choose a suitable parent ......
Read more >
File is not under 'rootDir' error in TypeScript | bobbyhadz
The "File is not under 'rootDir'" error occurs when we try to import ... 'rootDir' is expected to contain all source files.ts(6059) import...
Read more >
TSConfig Option: rootDir - TypeScript
Default : The longest common path of all non-declaration input files. ... is set, the default is instead the directory containing the tsconfig.json...
Read more >
Serverless Forums - Serverless Framework
File '../foo.ts' is not under rootDir. rootDir is expected to contain all source files · Utilize Webpack to allow setting the rootDir in ......
Read more >
Make sharing TypeScript code and types quick and easy
'rootDir' is expected to contain all source files. ts(6059) ... (When you do have to work this way for npm packages, make sure...
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