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
baseUrl in tsconfig is not supported #23
Comments
Hi @nkovacic, Thank you for creating an extended issue. Sadly the I have not yet found a solution for that issue and open for contributions. |
Is there any other way to atleast set a base path, so that absolute paths can be used? |
I never used absolute paths but I quickly checked and there seems to be a way: https://medium.com/@davidjwoody/how-to-use-absolute-paths-in-react-native-6b06ae3f65d1 |
The solution to this is to add @nkovacic for your configuration, your {
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
[
"module-resolver",
{
"root": ["./src"],
"alias": {
"@assets/*": "assets/*"
}
}
]
]
}
|
same question and I used solution of @solkaz, little different. .babelrc
tsconfig.json
|
@solkaz tried your solution and there seems to be a collision between ./src folder and some react-native internals. Probably should work in other JavaScript projects. |
@nkovacic what errors were you getting? |
Also having this issue with setting baseUrl in the tsconfig. Any valid workarounds or solutions on this? |
Even when changing the src main folder to app, paths still do not work. Can anyone share a complete example? |
The babel-plugin-module-resolver documentation shows how to use regular expressions to address this. So after some experimenting, this is a running example: tsconfig.json
babel.config.js
Using it is straight forward:
Took some trial and error but it's working fine now. |
This solution did not work for me. As far as I can tell, the I am on React Native 0.59.5 - I am not sure if that could explain the difference in behavior. |
I'm seeing the same issue |
Adding |
I don't think this is related to this template if you would like to have this feature consider submitting a PR. |
I've tried other solutions in this thread, in addition to trying to work around the issue with "@babel/register". It did not work. What worked for me was to edit Since I have this in
And I want to import from "[root]/src" as "src/...", here's my full const path = require("path")
module.exports = {
resolver: {
extraNodeModules: {
"src": path.resolve(__dirname, 'src'),
}
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
} If your module still isn't being found, try tweaking sourceExts. |
Neat solution @resolritter . That worked for me. Thanks! |
For everyone for whom using |
Saved my life @apedroferreira |
👍 to @apedroferreira |
Probably this could help somebody. It helped me: https://www.reactnativeschool.com/how-to-setup-path-alias-in-a-react-native-typescript-app |
Thank u @resolritter , your solution really helped me ) |
Thanks @apedroferreira! It worked for me with the |
Expected results
Setting baseUrl in tsconfig.json should enable absolute import paths.
index.ts
import Images from 'assets/images';
Observed results
What happened?
This error appears: error: bundling failed: Error: Unable to resolve module
assets/images
Logs
The text was updated successfully, but these errors were encountered: