【问题标题】:while running the react native app i got the error path could not be found within the project or in these directories:node_modules在运行本机应用程序时,我得到了在项目或这些目录中找不到错误路径:node_modules
【发布时间】:2022-12-14 03:38:14
【问题描述】:

在我的代码中,我使用的是 react-native: 0.66.1 并且我已经安装了 dotenv: ^10.0.0。 .env 文件代码

API_LOGIN=https://example.in/login

应用程序.js 文件

require('dotenv').config();
class UserLogin extends Component{
   //some code here
   apiCallHere=()=>{
      const url=process.env.API_LOGIN;
      fetch(url,{
         method: 'POST',  
         body: JSON.stringify({   
            email: email,
            password: password
         }),
         headers: new Headers({
            'Content-Type': 'application/json',
         })
      }).then(res => res.json())
      .catch(error => console.error('Error: ', error))
            
      .then((response) => {
         if (response.access_token != undefined) {
            this.setState({
               accessToken : response.access_token,
            });
            if(this.state.accessToken != ''){
               this.props.navigation.navigate('UserHomePage');
            }
         }
         else{
            alert('Unauthorised User');
         }
      })
   }
}

请帮我解决这个问题。我找不到问题所在。我是 React Native 的新手

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    看来问题出在导入方法上

    尝试更改导入要求

    import dotenv from 'dotenv'
    
    dotenv.config()
    

    请让我知道它是否有效

    【讨论】:

    • 这对我不起作用。
    • 请给我另一个解决方案
    猜你喜欢
    • 2022-06-16
    • 2022-11-12
    • 2020-02-17
    • 2023-04-08
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多