Create-react-app: Should not auto generate `tsconfig.json` for `js` project unexpectly.

Created on 20 Mar 2019  路  8Comments  路  Source: facebook/create-react-app

Is this a bug report?

No

Environment

npx: installed 1 in 12.203s
Path must be a string. Received undefined
C:\Users\zheng\AppData\Roaming\npm\node_modules\create-react-app\index.js

Environment Info:

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
  Binaries:
    Yarn: 1.13.0 - C:\Users\zheng\AppData\Roaming\npm\yarn.CMD
    npm: 6.8.0 - D:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 40.15063.674.0
    Internet Explorer: 11.0.15063.850
  npmPackages:
    react: ^16.8.3 => 16.8.3
    react-dom: ^16.8.3 => 16.8.3
    react-scripts: 2.1.5 => 2.1.5
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. create a javascript project, and some source code like xxx.js.
  2. create a type declared file for it, like xxx.d.ts.

Now each time we start the project used react-scripts start, it would generate a tsconfig.json unexpectly.

Expected Behavior

We just want to used the d.ts to declared some complicated types for some code, which flow and jsdoc could not implements.

I tried removed the d.ts temporary and start the project, then I recovery the d.ts file, and everything works well. The whole problem is just that react-scripts start generate the tsconfig.json and throw It looks like you're trying to use TypeScript but do not have typescript installed. unexpectly, for I just want used typed declartion instead of used Typescript.

needs investigation bug fix

Most helpful comment

For the time being we are going to exclude *.d.ts from this check. We might reconsider autogenerating tsconfig.json in the future.

All 8 comments

By the way, if the files start with '.', like .xxx.js and .xxx.d.ts, then everything works well too.

Maybe add a flag to disable auto generate tsconfig.json?

Now I delete tsconfig.json after yarn start every time...

In my opinion, if we really want to use Typescript, i'll create react-app with --typescript, otherwise we should never generate tsconfig without the developer agree, the developer should manual to do that if they want.

For the time being we are going to exclude *.d.ts from this check. We might reconsider autogenerating tsconfig.json in the future.

@zhengxiaoyao0716 I've been trying unsuccessfully to reproduce this issue. I also added some tests to make sure tsconfig.json isn't created when a .d.ts file is present in the app and those tests all passed.

Can you provide us with a minimal project that reproduces this issue?

Well, maybe this bug is aleady fixed since react-scripts 2.1.7? I tried that version and it not reproduced.

If I use 2.1.5, it can easly reporduced just by create an empty index.d.ts:
image
image
image

It looks like this was fixed so I'm going to close this issue: https://github.com/facebook/create-react-app/commit/df3e73f454f718dbb3f928ecf681a50467e5a18d#diff-9bb845f98191a45e63dd93f69abfb0e8

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fson picture fson  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

alleroux picture alleroux  路  3Comments

AlexeyRyashencev picture AlexeyRyashencev  路  3Comments

dualcnhq picture dualcnhq  路  3Comments