[英]Babel 7.18 doesn't transpile components outside the project root directory
[英]Babel - how to set aliases to outside of the root directory?
我有一个单体仓库:
domain/
entities/
account.ts
...
mobile/
src/
app.ts
node_modules/
package.json
babel.config.js
我想设置一个别名,以便app.ts
可以简单地调用:
import { Account } from 'domain/entities/account'
代替
import { Account } from '../../../domain/entities/account'
我试着这样做:
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')
}
}
]
]
}
}
但不幸的是,它不起作用。 它抛出:
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)
如何从主目录外部导入内容?
Go 到“域”文件夹并添加一个新文件 package.json,内容如下
{
"name": "domain"
}
现在你像这样导入
import { Account } from 'domain/entities/account'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.