【问题标题】:React-native-dotenv path could not be found within the project or in these directories:在项目或这些目录中找不到 React-native-dotenv 路径:
【发布时间】: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


【解决方案1】:

react-native-dotenv 作者在这里:正如上面评论中所说,Babel 配置看起来很棒。确保将 lib 安装为开发依赖项。

【讨论】:

    猜你喜欢
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2022-06-16
    • 2022-12-14
    • 1970-01-01
    相关资源
    最近更新 更多