Create-react-app: Adding the ability to disable auto-detect TypeScript files in project

Created on 1 Nov 2018  路  12Comments  路  Source: facebook/create-react-app

Is this a bug report?

No

Typscript is sometimes used to document some modules of a project and has only an informative role.
Can we add disabling auto-detect TypeScript in project?

proposal

Most helpful comment

@Timer I do not understand this argument. Consider this situation

  • I have a component library (all .js)
  • I manually add .d.ts files to make my components easier to consume in TypeScript projects
  • now I cannot run react-scripts (locally or in CI) without installing typescript

Note:

  • there is absolutely nothing to do or check for tsc here
  • there are no *.ts or *.tsx source files, only *.d.ts declaration and *.js source files
  • there is absolutely no need for importers to have typescript installed, either, so adding it as a dependency makes no sense

Suggestion:

  • add an exclude pattern (something like !*.d.ts) to globby, so that only actual TypeScript source files trigger the need to have typescript installed

All 12 comments

The auto-detection should have no adverse effect if you're not bundling TS files.

Is there a specific problem you're encountering?

I do not fully understand when the TS files are located.
But this code makes me think that the verification is carried out by simply determining the presence of files in the project folder.

function verifyNoTypeScript() {
  const typescriptFiles = globby('**/*.(ts|tsx)', { cwd: paths.appSrc });
  if (typescriptFiles.length > 0) {
    console.warn(
      chalk.yellow(
        `We detected TypeScript in your project (${chalk.bold(
          `src${path.sep}${typescriptFiles[0]}`
        )}) and created a ${chalk.bold('tsconfig.json')} file for you.`
      )
    );
    console.warn();
    return false;
  }
  return true;
}

We're probably not going to turn this behavior off unless you're being hit by a specific problem. Can you explain what's breaking?

There is no problem. This is more a question, a suggestion. I would not always like to connect a Typescript when the '.d.ts' files are in the project folder

If you have .d.ts files they should be associated to a TypeScript version. Not installing TypeScript is a behavior prone to breaking, so what we're doing here is correct.

@Timer I do not understand this argument. Consider this situation

  • I have a component library (all .js)
  • I manually add .d.ts files to make my components easier to consume in TypeScript projects
  • now I cannot run react-scripts (locally or in CI) without installing typescript

Note:

  • there is absolutely nothing to do or check for tsc here
  • there are no *.ts or *.tsx source files, only *.d.ts declaration and *.js source files
  • there is absolutely no need for importers to have typescript installed, either, so adding it as a dependency makes no sense

Suggestion:

  • add an exclude pattern (something like !*.d.ts) to globby, so that only actual TypeScript source files trigger the need to have typescript installed

Facing the exact same issue !
I upgraded my project from react-scripts 1.1.5 to 2.1.1.
We have no typescript files whatsoever, but when I run npm start, I get this:

We detected TypeScript in your project (src/packages/some_package_name/some_private_package/node_modules/camel-case/camel-case.d.ts) and created a tsconfig.json file for you.

It looks like you're trying to use TypeScript but do not have typescript installed.
Please install typescript by running npm install typescript.
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).

And if I delete the tsconfig file and run it again, this repeats.

That sounds like a bug @MohammedSiddiqui10p, why is it picking up your node_modules?

We have a git submodule in our project because we have to consume a private package which isn't published anywhere. So we have a .gitmodules file in our root which tells git where to place our private package.

[submodule "src/packages/some_private_package/some_name"]
    path = src/packages/some_private_package/some_name
    url = [email protected]:some_github_link.git

I'm getting a similar issue to @MohammedSiddiqui10p:

We detected TypeScript in your project (src\node/node_modules/npm/node_modules/worker-farm/index.d.ts)

For me, it's because my UI is built as part of a Maven build that installs node (hence src\node/node_modules, looks like there's some unrelated dodgy path concatenation there too).

The fix for me was to change my build config to install Node into the target directory instead of src.

The real issue
As a TL;DR, the issue looks to be occurring for anyone who has node packages in their project outside of the usual node_modules folder.

same problem

I'm having this issue as well. I'm using Bit, which embeds packages in my src folder, along with their dependencies in a node_modules folder, and some of those dependencies have .d.ts files. Now I can't even run yarn start. Thoughts?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdamian3 picture rdamian3  路  3Comments

AlexeyRyashencev picture AlexeyRyashencev  路  3Comments

barcher picture barcher  路  3Comments

Aranir picture Aranir  路  3Comments

stopachka picture stopachka  路  3Comments