You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this will start permitting absolute imports in TS apps.
Reacted by Niek Kruse, Bjarke Hesthaven Søndergaard, Peter Oesteritz, kevinkam, Teddy Cross, Mikael Midtgaard, scotthovestadt, Daniel Fernandez, Kevin Gonnord, Janeene Beeforth and 27 more
We use the same as @tkazec, so that instead of having to have a dozen different absolute paths (plus paths for files that were under src itself...I'm not sure how src/App.ts would be referenced without the src prefix present) we only had one, and thus had a lot less risk of a name clash between one of our folders and an npm package name.
@jamesg1 That's been working for me for over a year too, but on this new project, whenever I run yarn start, the baseUrl entry is removed from tsconfig.json!
We now support setting baseUrl in tsconfig.json (and jsconfig.json). Currently you can only set it to node_modules (the default) and src. We are hoping to add support for aliases in the near future and may look at relaxing the restriction on baseUrl.
NODE_PATH is now deprecated and since you can just set baseUrl directly I think this can be closed.
Activity
niekert commentedon Nov 3, 2018
Out of curiosity, would this allow absolute imports in TS apps created with create-react-app?
I've been trying to get it working and remember setting the
NODE_PATHfor JS projects. Loving the Typescript support 🙏Timer commentedon Nov 3, 2018
Yes, this will start permitting absolute imports in TS apps.
tddyco commentedon Nov 5, 2018
Will this work with
NODE_PATH=.as well?I use this because it forces referencing
src/, removing any ambiguity as to what is being imported.Timer commentedon Nov 5, 2018
Not sure if we'll allow
.or not, there's always #5118 which will let you import via@/.dawnmist commentedon Nov 6, 2018
We use the same as @tkazec, so that instead of having to have a dozen different absolute paths (plus paths for files that were under
srcitself...I'm not sure howsrc/App.tswould be referenced without thesrcprefix present) we only had one, and thus had a lot less risk of a name clash between one of our folders and an npm package name.unzico commentedon Nov 18, 2018
@niekert
If you're looking for a way to enable absolute path imports, see #5118 (comment)
jamesg1 commentedon Feb 11, 2019
Adding
"baseUrl": "./src",to mycompilerOptionsoptions intsconfig.jsonworked for me.mindjuice commentedon Mar 5, 2019
@jamesg1 That's been working for me for over a year too, but on this new project, whenever I run
yarn start, thebaseUrlentry is removed fromtsconfig.json!Anyone have a way to prevent this?
jamesg1 commentedon Mar 5, 2019
@mindjuice Yeah I think there was a change which resets the baseUrl might have to use react rewired.
See #5118 (comment)
agido-freudenreich commentedon Mar 5, 2019
@mindjuice The tsconfig is rewritten on every start. You have to use
extends(#5645 (comment))Added users context
iansu commentedon Apr 23, 2019
We now support setting
baseUrlintsconfig.json(andjsconfig.json). Currently you can only set it tonode_modules(the default) andsrc. We are hoping to add support for aliases in the near future and may look at relaxing the restriction onbaseUrl.NODE_PATHis now deprecated and since you can just setbaseUrldirectly I think this can be closed.