I'm facing an issue with my monorepo structure:
domain/
entities/
account.ts
...
mobile/
src/
app.ts
node_modules/
package.json
babel.config.js
The problem I'm trying to solve is setting up an alias for the file app.ts
so that it can be imported like this:
import { Account } from 'domain/entities/account'
Instead of the longer path:
import { Account } from '../../../domain/entities/account'
I attempted a solution using the following code snippet:
const path = require('path')
module.exports = (api) => {
api.cache(true)
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['module:react-native-dotenv', {
moduleName: 'react-native-dotenv'
}],
[
'module-resolver',
{
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx'
],
alias: {
domain: path.resolve(__dirname, '../domain')
}
}
]
]
}
}
Unfortunately, this approach is not working as expected. It throws the error message:
Error: Unable to resolve module /home/kibe/work/iros-customer-frontend/domain/entities/account from ...
None of these files exist:
* ../domain/entities/account(.js|.jsx|.ts|.tsx)
I would appreciate any insights on how to successfully import modules from directories outside the main one.