简体   繁体   English

为什么我在反应原生 windows 时遇到 os 模块错误

[英]Why I'm getting os module error in react native windows

I'm trying to build RDP application in react-native-windows.But I'm getting Unable to resolve module os error even though the os module is already installed.我正在尝试在 react-native-windows 中构建 RDP 应用程序。但是即使已经安装了 os 模块,我也会遇到 Unable to resolve module os 错误。

What I've tried:我试过的:

  • reset cache重置缓存
  • delete node_modules folder and installed again using npm install.删除 node_modules 文件夹并使用 npm install 再次安装。

Code:代码:

 import React, { Component } from 'react'; import { Text, View, StyleSheet, TouchableOpacity, TextInput, Button } from 'react-native'; class App extends Component { constructor() { super() this.state = { Ip: '', UserName: '', Password: '', } } rdp = () => { var rdp = require('node-rdp'); rdp({ address: this.state.Ip, username: 'DOMAIN\'+ 'this.state.UserName', password: this.state.Password }).then(function () { console.log('At this, point, the connection has terminated.'); }); } render() { return ( <View style={styles.Main}> <Text style={styles.Title}>Remote Desktop Connection</Text> <View style={styles.container}> <View style={styles.InputFieldView}> <Text>Ip Address: </Text> <TextInput style={styles.InputField} onChangeText={(e) => { this.setState({ Ip: e }) }} /> </View> <View style={styles.InputFieldView}> <Text>UserName: </Text> <TextInput style={styles.InputField} onChangeText={(e) => { this.setState({ UserName: e }) }} /> </View> <View style={styles.InputFieldView}> <Text>Password: </Text> <TextInput style={styles.InputField} onChangeText={(e) => { this.setState({ Password: e }) }} /> </View> <Button title="Submit" onPress={() => this.rdp()} /> </View> </View> ) } } const styles = StyleSheet.create({ Main: { flex: 1, alignItems: "center" }, container: { justifyContent: "center", alignItems: "center", }, InputFieldView: { alignItems: 'flex-start', marginBottom: 10, }, InputField: { width: 300, borderRadius: 3, }, Title: { marginTop: 100, marginBottom: 40, fontSize: 30, } }) export default App;

Error:错误:

error: Error: Unable to resolve module os from K:\native_windows\demo\node_modules\node-rdp\lib\rdp-file.js: os could not be found within the project or in these directories:
  node_modules

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  1 | var Q = require('q');
  2 | var fs = require('fs');
> 3 | var os = require('os');
    |                   ^
  4 | var path = require('path');
  5 | var defaults = require('lodash.defaults');
  6 | var sanitize = require("sanitize-filename");
    at ModuleResolver.resolveDependency (K:\native_windows\demo\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:129:15)
    at DependencyGraph.resolveDependency (K:\native_windows\demo\node_modules\metro\src\node-haste\DependencyGraph.js:288:43)
    at Object.resolve (K:\native_windows\demo\node_modules\metro\src\lib\transformHelpers.js:129:24)
    at resolve (K:\native_windows\demo\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:33)
    at K:\native_windows\demo\node_modules\metro\src\DeltaBundler\traverseDependencies.js:412:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (K:\native_windows\demo\node_modules\metro\src\DeltaBundler\traverseDependencies.js:411:33)
    at processModule (K:\native_windows\demo\node_modules\metro\src\DeltaBundler\traverseDependencies.js:140:31)
    at addDependency (K:\native_windows\demo\node_modules\metro\src\DeltaBundler\traverseDependencies.js:230:18)
    at async Promise.all (index 0)

Using this library for rdp: https://www.npmjs.com/package/cross-node-rdp将此库用于 rdp: https://www.npmjs.com/package/cross-node-rdp

var fs = require('fs');
var os = require('os');

This library may be used only with NodeJS这个库只能与 NodeJS 一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native 在 App.js 中找不到模块 webpack 错误 - 我正在使用 Ubuntu - React Native cannot find module webpack error in App.js - I'm using Ubuntu 为什么我收到querySelectorAll()错误 - why i'm getting a querySelectorAll() error 为什么我获取的 blob 音频文件没有播放? 我正在使用 React Native Track Player - Why isn't my fetched blob audio file getting played? I'm using React Native Track Player 需要帮助弄清楚为什么我在 React Form 中收到错误 - Need help figuring out why I'm getting an error in a React Form 为什么在将数据设置为上下文时出现最大更新深度超出错误 (React) - Why I'm getting maximum update depth exceeded error when setting data to context (React) firebase.database 不是 function 为什么我在反应本机应用程序中收到此错误? - firebase.database is not a function why I am getting this error in react native app? 为什么在尝试运行新的 React Native 项目时出现错误 - Why am I getting an error when trying to run a new react native project 为什么React fetch忽略了我得到的JSON数据? - Why is React fetch ignoring the JSON data I'm getting? 为什么我得到 Functions are not valid as a React child? - Why I'm getting Functions are not valid as a React child? 我在使用 React 制作的项目中遇到未定义的错误 - I'm getting an undefined error in my project made with React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM