【发布时间】:2022-11-12 09:59:32
【问题描述】:
我已经在我的react-native-project(非博览会)中安装了 react-native-dotenv 并且我收到了这个错误
error: Error: Unable to resolve module path from C:\XXX\XXX\XXX\node_modules\react-native-dotenv\index.js: path could not be found within the project or in these directories:
node_modules
..\..\..\..\..\node_modules
1 | const {readFileSync, statSync} = require('fs')
> 2 | const path = require('path')
| ^
3 | const dotenv = require('dotenv')
4 |
5 | function parseDotenvFile(path, verbose = false) {
在线阅读,人们说您需要修改我所做的babel.config
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module:react-native-dotenv',
{
envName: 'APP_ENV',
moduleName: '@env',
path: '.env',
},
],
],
};
但它仍然会重现相同的错误,并且大多数这些修复都是针对世博会的,我从未与世博会合作过,我尝试了以下
https://stackoverflow.com/a/64227089/5413196
https://github.com/goatandsheep/react-native-dotenv/wiki/Migration-Guide
https://github.com/facebook/react-native/issues/29314
而且我仍然遇到同样的错误,有人可以建议如何解决吗?
【问题讨论】:
标签: javascript reactjs react-native