baseUrl in tsconfig is not supported
See original GitHub issueExpected results
Setting baseUrl in tsconfig.json should enable absolute import paths.
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es6"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"strictPropertyInitialization": false,
"target": "esnext",
"baseUrl": "./src",
"paths": {
"@assets/*": ["assets/*"]
}
},
"exclude": ["node_modules"]
}
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
Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module `assets/images` from `D:\App\src\pages\Splash\Splash.tsx`: Module `assets/images` does not exist in the Haste module map
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (D:\App\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:209:1301)
at ResolutionRequest.resolveDependency (D:\App\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:83:16)
at DependencyGraph.resolveDependency (D:\App\node_modules\metro\src\node-haste\DependencyGraph.js:238:485)
at Object.resolve (D:\App\node_modules\metro\src\lib\transformHelpers.js:180:25)
at dependencies.map.result (D:\App\node_modules\metro\src\DeltaBundler\traverseDependencies.js:311:29)
at Array.map (<anonymous>)
at resolveDependencies (D:\App\node_modules\metro\src\DeltaBundler\traverseDependencies.js:307:16)
at D:\App\node_modules\metro\src\DeltaBundler\traverseDependencies.js:164:33
at Generator.next (<anonymous>)
at step (D:\App\node_modules\metro\src\DeltaBundler\traverseDependencies.js:266:307)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:34
- Comments:21
Top Results From Across the Web
baseUrl of tsconfig.json does not work - Stack Overflow
The problem here is that the TypeScript compiler does not update the path in your JS files and the JavaScript Engine knows nothing...
Read more >How can I get TypeScript baseUrl to work? #12175 - GitHub
The v1.18.0 release notes mention support for baseUrl in tsconfig.json. I'm not able to make it work. Here is a minimal example: ...
Read more >tsconfig.json for using baseUrl and importing json - Reddit
I am about to transform an existing nodejs app to typescript. Seeing a lot of `../..` patterns in the paths I was happy...
Read more >paths and baseUrl | ts-node - TypeStrong · GitHub
You can use ts-node together with tsconfig-paths to load modules according to the paths ... paths and baseUrl ... Do not forget to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
metro.config.jsand use extraNodeModules.Since I have this in
tsconfig.jsonAnd I want to import from “[root]/src” as “src/…”, here’s my full
metro.config.jsconfiguration:If your module still isn’t being found, try tweaking sourceExts.
This solution did not work for me. As far as I can tell, the
babel.config.jsfile is not even being read in my environment; I put some gibberish at the bottom of the file, and the application still built and loaded (minus the fact this error came up).I am on React Native 0.59.5 - I am not sure if that could explain the difference in behavior.