-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Add baseUrl and paths in tsconfig.json and jsconfig.json #5645
Comments
You may be interested: #5118 (comment) |
@tanduong if we use yarn-pnp, we have no |
All of these solutions don't resolve some reasons to just typescript "paths" feature. And without "baseUrl" set to something, paths don't work at all. I really think that baseURL (at least set to .) should be something we can opt into. |
I'm having this issue. I have |
As a hack/work around, one can set the desired configurations in a different {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"svg/*": ["src/svg/*"],
"components/*": ["src/components/*"]
}
}
}
in {
"extends": "./paths.json"
} |
One of the side-effects of setting |
@ianschmitz tsconfig-paths-webpack-plugin can works with current webpack config. We can use tslint to show warn of 「using an absolute path of "src/Foo"」 |
It just works with react-scripts@2.0.5 and react-app-rewire-typescript-babel-preset@3 |
We have our own version of One solution I think could work is to allow it to be set whenever NODE_PATH is set to {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["src/*"]
}
}
} |
It seems not work at CRA@2.0.4 |
@babakness I would name that Also, why not just |
I've tried extending tsconfig.json but it's still unable to resolve, I'm using cra@2.1.1 |
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. |
What is the current recommendation for getting absolute paths to work? It would be great if it worked with TypeScript's built in way of doing this. |
I am trying to use |
@ChristianIvicevic I had the same issue. Once I realized that's not a supported path, I 🤷♂️ |
This issue is disappointing, since I want to avoid weird relative paths, especially something like |
It is frustrating. It doesn't make sense that anyone would have to eject for something so small like this. |
Some hack ideas I have is to configure the file system to prevent overriding the file by CRA and to try the new TypeScript 3.2 feature where you can I don't have time to hack it right now but honestly one reason I've not upgraded CRA2 since the CRA2 should at least allow us to do what we want at "our own risk". |
The more important question is why is CRA changing this file? What's the underlying problem or concern? I'd love to know, because perhaps someone can come up with a better solution. |
Reasoning is here: #5585 (comment) I think users should be allowed to change config even if it is not supported at their own risk. |
I actually attempted this as well as described here: #5645 (comment) Unfortunately CRA had a meltdown and basically ignores the settings. |
Nothing works for |
And here I though I can use lerna wit ts packages and just set up paths to have HMR :D |
Are there any improvements to this? |
If it doesn't work and you are using monorepo like me. {
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@packages/*": ["../packages/*"]
}
}
} Hope to solve your problem. |
If you're not using TypeScript, set
, then update your imports to remove |
Why can't people simply include "src" in absolute imports? Easier to understand, makes it much more obvious which files are internal and which are external deps. Explicit better than implicit. |
I had to use this in jsconfig.json file in my project root for vscode to serve my application to localhost. Not having 'paths' defined did not work. Also having an .env file in addition to jsconfig.json also did not work. I had to delete the .env file.
|
For those of you still having problems with absolute paths and nested folders path
|
Has anyone gotten typescript references to work? Using the recommended
I'm getting this error: References work fine for non-CRA packages but not for a CRA package. Strangely enough, CRA starts compiling when removing both |
Because, for example, you have a main root package1 and a nested package2 (using yarn workspaces for instance)
It would be much easier to have "paths" in both packages and import everything using the aliases provided there. It would be:
|
Have tried many of the solutions for TS posted here and on #5118, and none of them seems to work as of now (using latest version of CRA). |
I tried to use absolute import as describe here : https://create-react-app.dev/docs/importing-a-component#absolute-imports (using but i get conflict between one folder of the project and node_modules when i try to import through |
@LoiKos please file a new issue and fill in the issue template. |
tsconfig.json
orjsconfig.json
:see #5118
This will help VSCode and other IDE to resolve path in TypeScript & JavaScript.
The text was updated successfully, but these errors were encountered: