-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the tsconfig file to configure the alias does not take effect #8909
Comments
And the hit "compilerOptions.paths must not be set (aliased imports are not supported)" |
@lnwu The editor is webstorm! The problem has been resolved and you need to install react-app-rewired and configure both the ts path alias Settings and the webpack alias Settings |
Found that can do it just using baseurl in tscofig, so we can using
that refs src/components |
@lnwu If "src/" is added to each introduction, it is still not convenient, and it is better to use the shortest path. I am not sure why the create-react-app scaffolding removes the paths option when compiling, is this the default? For this reason, most people use react-app-rewired to change the path configuration! |
It is definitely bad to modify user's custom I found a workaround: Move current {
"extends": "./tsconfig.base.json"
} |
@JounQin if I do what you proposed I get Have you encountered this error? |
@3stacks I didn't get this error. |
@VitaminCtea
|
The best alternative right now is to define import { MyComponent } from "src/components" |
This worked for me! Used it for importing types from an adjacent package in a monorepo. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue. |
Just for future reference:
|
* wip? * fixes * wip * connect client every time * pool * make server use ts * more * fix imports * implicit any true in frontend * fixes * refactor fronted src/api * fix imports * noimplicitany stuff * mess around double tsconfig more * revert PuzzleList * scaffolding for new puzzle list * more scaffolding * ts * more fixes * mess around with types * set up shared path * tsconfig updates * tsconfig.base.json ref: facebook/create-react-app#8909 (comment) * restore old welcome page * add localstorage gate for new puzzle list * restore old upload functionality too * fix add event
Is there at least a good reason for not allowing path aliases in CRA? |
Worked perfectly! Thanks for this. |
It could be nice to write why, and at least write in the advanced usage that you can't do it. Deleting the paths section in the tsconfig is really disturbing, the first time I didn't know why my code was deleted because once the application is built the console is cleared. |
Doesn't look like anyone from the create-react-app team is getting notifications on this since it was closed by stale bot. Further discussion should probably be continued in a new issue/feature-request, unless this one can be reopened. |
Just ran into this. Hoping to see a resolution some time in the future. |
I don't think any of create-react-app team is going to comment on this, so I solved this by creating paths.json file
and then extended it in the tsconfig.json file
|
I just tried it (again). The code completion in VSCode works for those paths, but it won't compile and outputs the following error message:
Interestingly, when I restart my react app via So it doesn't work for me with |
@ramishenouda what version of Is anybody aware of any workaround to get aliases working in CRA? I've tried this, but so far no luck. My symptoms are the same as the last poster, i.e., autocomplete validates the syntax but the |
@zaneclaes @chriszirkel
TypeScript aliases work fine in CRA with a bit of help of
We've been using this setup for more than a year now and we had absolutely no problems with it. It works on the latest version of CRA and the previous major version as well, TS 3.7+ (potentially earlier version as well). |
Thank you; this worked, and saved me many hours. I had tried a different eject/alias tool (linked in the last post), but Craco did the trick. I specifically used the Use aliases from tsconfig.json (source: "tsconfig") example from the craco-alias docs. |
Do you guys still have the warning when building ? Even though aliases are working properly ?
|
Yes, but it doesn't matter for us. |
I got a same issue. |
Thanks it works for me. I used it to refer the types module for ploty.js dist package. |
Can you please send me your configuration file, I'm trying to set an alias for my images folder but cra isn't even detecting files called with the base url. |
This worked once I also installed craco (npm i @craco/craco) and set up a craco.config.js file:
Finally, replace react-scripts with craco in package.json:
NOTE: you will still get a warning in the console, but it works. |
It's a bit hard to understand how something as basic as aliases are not supported by CRA. Even with CRACO it's still cumbersome to get it working. |
Unfortunately, this workaround is no longer working on cra@5 :( |
alias in CRA@5 works without any workaround. just modify the path config in tsconfig.json update: it works with craco, craco-alias. but craco is not fully support CRA@5 now. |
I'm going to create an example here to reproduce the problem, but with my current project, it didn't work. I end up using the |
Worked like a charm! Thanks! |
I've been struggling to get this to work. Thanks for all the solutions. Although the But seriously, is someone really telling me that no one from the React team is going to explain or acknowledge this in any way at all. |
@MrBrN197 Switch to nextjs, it supports client side rendering. |
Was this ever answered? I want to use aliases but it seems like it's discouraged. |
Next JS is the way to go now. Ditch CRA. |
You may be right @youneshenniwrites. It seems development in the project is a bit stale? |
Migrated CRA to Vite. Working very well.
|
Vite is also a viable choice. |
Update 2023, CRA still sucks. Not able to set the path as per my need. Tried the |
@ThePiyushAggarwal Is the |
@v4voloshyn I think you may be thinking of v5 as the latest version. It is latest but it is 2 years old and |
The project was generated using the create-react-app scaffolding, and the paths option was removed when I used the tsconfig.json file to configure the path alias! Then I tried to use the extends property in the tsconfig.json file to connect to the external path configuration file, but it didn't work either! Using the customize-cra plug-in in conjunction with the above configuration file does not take effect. How do I configure it? Why doesn't the scaffolding support?
React version: 16.13.1
react-scripts version: 3.4.1
The tsconfig.paths. json path file configuration:
Customize -cra configuration file:
Sample file contents:
import App from 'components/App'
Warning message:
Error message:
Please help me thank you!
The text was updated successfully, but these errors were encountered: