D
D
dark_king_132020-04-28 20:27:26
typescript
dark_king_13, 2020-04-28 20:27:26

How to set up react-app for typescript?

Such situation. I create an application using yarn create react-app app-name, then yarn ejectrun it and write in the webpack config

...
resolve: {
      modules: ['node_modules', 'src', paths.appNodeModules].concat(
        modules.additionalModulePaths || []
      ),
...

Now I can create the following structure:
--src
----pages
------index.js
------Auth
--------Auth.jsx
----App.jsx

In the index.js file In Auth.jsx the component itself And now in App.jsx I can import it with this: And everything works. Without any ./ ../../ etc. But if you ground js -> ts, jsx -> tsx, then everything stops working.export { default as Auth} from './Auth/Auth'

import { Auth } from 'pages'

Mistakes

5ea865f8dec59900023819.png
5ea865fe678f9530714493.png


As I understand it, you need to add something to webpack, but I don’t know what.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dark_king_13, 2020-05-01
@dark_king_13

Added intsconfig.json

"compilerOptions": {
  ...
  "baseUrl": "./src",
  ...

And everything worked

O
Oleg Gamega, 2020-04-28
@gadfi

ts is out of the box in cra

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question