create-react-app: Typescript: Simplified typescript steps not working
Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes
Environment
Environment: OS: macOS 10.14 Node: 10.12.0 Yarn: 1.10.1 npm: 6.4.1
Packages: (wanted => installed) react: ^16.5.2 => 16.5.2 react-dom: ^16.5.2 => 16.5.2 react-scripts: 2.0.5 => 2.0.5
Steps to Reproduce
I noticed that typescript was added to the project officially. I went ahead and created a new project and followed in the instructions detailed in https://github.com/facebook/create-react-app/commit/3c11efe206d7ffe1ea75ebf32aa207ddfd8c0499 but they did not work. I’ve walked back through the commit history and tried some of the previously detailed steps to no avail. Neither creating a tsconfig.json or a tsconfig.json with {}
in the file worked for me either.
Followed instructions listed at https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/adding-typescript.md
- npx create-react-app <app>
yarn add typescript @types/react @types/react-dom @types/jest
- Rename
src/index.js to src/index.tsx
Expected Behavior
I expected the app to start correctly
Actual Behavior
Received an error .
Could not find a required file.
Name: index.js
Reproducible Demo
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 18 (7 by maintainers)
Please use this new method instead of
yarn link
:npx create-react-app@next app-name --scripts-version=2.0.6-next.c662dfb0 --typescript
For existing projects, run
yarn unlink react-scripts
and installyarn add react-scripts@2.0.6-next.c662dfb0
.Let me know if that works for you!
@sebasmurphy you can close this 😃
Things that land in master might not get released for weeks or even months (in the worst case). When things get released, they appear in the changelog and on the releases page. 😉
@nielsdB97 It’s because I didn’t publish the other required packages, sorry.
Please wait for the official release or use this method instead:
npx create-react-app@next app-name --scripts-version=2.0.6-next.c662dfb0 --typescript
Older method using
yarn link
:git clone git@github.com:facebook/create-react-app.git
cd create-react-app
yarn
cd packages/react-scripts/
yarn link
cd ~/your/projects/folder
npx create-react-app app-name
cd app-name
yarn link react-scripts
yarn start
I believe the issue is the fact that - while the PR was merged in - they have not yet published a new version of
react-scripts
which includes these changes.Last publish was 9 days ago: https://www.npmjs.com/package/react-scripts
However when I tried to import scss files, the following error appears:
The
create-react-app
folder is the root folder ofcreate-react-app
clone. It seems there are some issues in resolving symbolic links that react-scripts does not know that root path of the project. I addedconsole.log(__dirname)
at the very first line of the script, found out that it wasn’t inside node_modules, but the cloned directory. Perhaps (https://github.com/strothj/react-app-rewire-typescript-babel-preset/issues/30) would be a safer method.Not sure, but would be awesome if it was at least published to canary or a different tag.
@gaearon yeah that’s my bad, I jumped the gun a bit. I saw some tweets and discussion on
hnews
and assumed a new version had been released with the changes. However the aforementioned posts were just referencing the fact that the code had been merged. 😞@gaearon Can we put
@types/react
into the repo ofreact
?