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.

rootDir warning even when set to './src'

See original GitHub issue

Current Behavior

It complains that rootDir is set to ./ when it’s not

Expected behavior

It should not complain about it since rootDir is correctly set to ./src

Additional context

[tsdx]: Your rootDir is currently set to "./". Please change your rootDir to "./src".
TSDX has deprecated setting tsconfig.compilerOptions.rootDir to "./" as it caused buggy output for declarationMaps and occassionally for type declarations themselves.
You may also need to change your include to remove "test", which also caused declarations to be unnecessarily created for test files.

tsconfig.json:

{
    "include": ["src", "types"],
    "compilerOptions": {
      "target": "esnext",
      "module": "esnext",
      "lib": ["esnext", "dom"],
      "importHelpers": true,
      "declaration": true,
      "sourceMap": true,
      "rootDir": "./src",
      "noImplicitAny": false,
      "noImplicitThis": true,
      "noUnusedLocals": false,
      "noUnusedParameters": false,
      "noFallthroughCasesInSwitch": true,
      "moduleResolution": "node",
      "baseUrl": "./",
      "esModuleInterop": true,
      "resolveJsonModule": true
    },
    "exclude": ["node_modules", "**/*.spec.ts"]
  }

Your environment

Software Version(s)
TSDX ^0.13.1
TypeScript ^3.8.3
Browser -
npm/Yarn -/1.22.4
Node v12.16.1
Operating System WSL 2 Ubuntu 18.04

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
agilgur5commented, Jul 18, 2020

Well you already had src, src/* isn’t really any different except that it avoids this error. Using files means only things that are actually imported are compiled, which is even better. It’s also in your tsconfig.build.json and you only want to include src when building. If you include files that aren’t in src, TS will type-check, compile, and create declarations for those files too. In the past that has meant erroneously adding tests’ or examples’ declarations into dist, which shouldn’t be there as library users don’t use those (and that causes bloating as well as potential side-effects due to how TS merges declarations)

1reaction
agilgur5commented, Jul 18, 2020

@gustavopch thanks for the repro. Very weird, it is indeed creating a dist/src/ directory even though you don’t have a src/src/ directory. There are no other directories created either, so doesn’t seem like you’re importing from another directory. 🤔

The check is here, which is inside a deprecated function that moves type declarations from dist/src/ to just dist/: https://github.com/formium/tsdx/blob/f0963cb2d77f00bcd8606f8e4b99250972d81b02/src/deprecated.ts#L13-L21

I’m pretty confused as to why that’s happening, maybe related to new TS version you’re using. However, I was able to workaround the issue by using "files": ["./src/index.ts"] instead of the "include": ["./src"]

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 >
File is not under 'rootDir' error in TypeScript | bobbyhadz
The "File is not under 'rootDir'" error occurs when we try to import something from a file that is not located under the...
Read more >
Support for roots and modulePaths in jest.config.js files
It makes the red underline and yellow exclamation mark warning go away. But I still cannot navigate to the source import file with...
Read more >
Solving warning: “Experimental support for decorators is a ...
“outDir”: Basically where the builded files will be placed. Probably before they go to production environment. · “rootDir”: You should fill this out...
Read more >
Understanding TypeScript Configuration Options
TypeScript will compile all files under src/ directory, but if you want to include ... The rootDir setting, if not explicitly set, defaults...
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