tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

rootDir warning even when set to './src'

Open Ponjimon opened this issue 5 years ago • 9 comments
trafficstars

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

Ponjimon avatar Apr 07 '20 12:04 Ponjimon

Can you provide a minimal reproduction? Can't say what's going on otherwise.

There is a different code-path where it could be hit, but it's highly unlikely a user has it as you'd need to have a src/src/ directory structure, which would be very confusing usage.

agilgur5 avatar Apr 07 '20 13:04 agilgur5

@agilgur5 Just happened to me:

  • Clone https://github.com/gustavopch/firebase-event-sourcing
  • Run yarn to install the dependencies
  • Run yarn build
  • See the error

gustavopch avatar Jul 18 '20 03:07 gustavopch

@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"]

agilgur5 avatar Jul 18 '20 16:07 agilgur5

You can also use "include": ["./src/*"] which seems to work fine as well.

agilgur5 avatar Jul 18 '20 17:07 agilgur5

@agilgur5 Wont' that cause some undesired side-effect like ignoring any files that are not placed directly in the src folder?

gustavopch avatar Jul 18 '20 18:07 gustavopch

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)

agilgur5 avatar Jul 18 '20 18:07 agilgur5

@agilgur5 Unfortunately, dist/application/definitions is not generated when I apply that workaround. Without the ./src/* workaround, it's generated.

gustavopch avatar Jul 19 '20 03:07 gustavopch

so no fix for this issue yet rt, cause the work around is not working

ghost avatar Oct 06 '22 05:10 ghost

Hi, I am also getting this error when I start a project using pnpm run start

image

here is my tsconfig.json

{ "include": ["src"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, "declaration": true, "sourceMap": true, "baseUrl": "src", "strict": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "moduleResolution": "node", "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "resolveJsonModule": true, "noImplicitAny": false } }

here is my tsdx.config.json

const copy = require('rollup-plugin-copy'); const replace = require('@rollup/plugin-replace');

module.exports = { rollup(config, opts) { config.plugins = config.plugins.map((p) => p.name === 'replace' ? replace({ 'process.env.NODE_ENV': JSON.stringify(opts.env), preventAssignment: true, }) : p );

config.plugins.push(
  copy({
    targets: [{ src: 'src/*.d.ts', dest: 'dist/' }],
  })
);

return config;

}, }

hassanprodeveloper avatar Jan 16 '24 17:01 hassanprodeveloper