简体   繁体   English

谷歌云日志 Node.js React Native 中的库导入

[英]Google Cloud Logging Node.js library import in React Native

I am having difficulty importing the @google-cloud/logging npm package in my React Native project.我在我的 React Native 项目中导入@google-cloud/logging npm package 时遇到困难。 I tried with npm install @google-cloud/logging and yarn add @google-cloud/logging but when I try to use it in my code via const {Logging} = require('@google-cloud/logging');我尝试使用npm install @google-cloud/loggingyarn add @google-cloud/logging但是当我尝试通过const {Logging} = require('@google-cloud/logging');在我的代码中使用它时or import {Logging} from '@google-cloud/logging';import {Logging} from '@google-cloud/logging'; commands I am getting a stream not found exception.命令我收到 stream 未找到异常。

Exception:例外:

error: Error: Unable to resolve module stream from 
C:\Users\User\Documents\repos\project\node_modules\@google-cloud\logging\build\src\index.js: 
stream could not be found within the project.

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-*
  26 | // eslint-disable-next-line @typescript-eslint/no-var-requires
  27 | const pumpify = require('pumpify');
> 28 | const streamEvents = require("stream-events");
     |                               ^
  29 | const middleware = require("./middleware");
  30 | exports.middleware = middleware;
  31 | const metadata_1 = require("./utils/metadata");

at ModuleResolver.resolveDependency (C:\Users\User\Documents\repos\project\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:191:15)
    at DependencyGraph.resolveDependency (C:\Users\User\Documents\repos\project\node_modules\metro\src\node-haste\DependencyGraph.js:353:43)
    at Object.resolve (C:\Users\User\Documents\repos\project\node_modules\metro\src\lib\transformHelpers.js:271:42)
    at resolve (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:571:33)
    at C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:587:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:586:33)
    at C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)

I tried deleting node_modules folder from the project and installing the packages again, resetting the Metro cache .我尝试从项目中删除node_modules文件夹并再次安装包,重置Metro cache The error still persists.错误仍然存在。

I have "react-native": "~0.63.4" and "@google-cloud/logging": "^9.6.1" in my package.json我的package.json中有"react-native": "~0.63.4""@google-cloud/logging": "^9.6.1"

Is there a way to implement Google Cloud Logging in a React Native project?有没有办法在React Native项目中实现Google Cloud Logging

UPDATE 1更新 1

I resolved the stream exception with yarn add stream command.我使用yarn add stream命令解决了stream异常。 Now it asks for the fs package which I added with yarn but now I receive the following error:现在它要求我用yarn添加的fs package 但现在我收到以下错误:

Error: While trying to resolve module `fs` from file `C:\Users\User\Documents\repos\project\node_modules\@google-cloud\logging\build\src\utils\metadata.js`, the package `C:\Users\User\Documents\repos\project\node_modules\fs\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`C:\Users\User\Documents\repos\project\node_modules\fs\index.js`. Indeed, none of these files exist:

  * C:\Users\User\Documents\repos\project\node_modules\fs\index.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * C:\Users\User\Documents\repos\project\node_modules\fs\index.js\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
    at DependencyGraph.resolveDependency (C:\Users\User\Documents\repos\project\node_modules\metro\src\node-haste\DependencyGraph.js:376:17)
    at Object.resolve (C:\Users\User\Documents\repos\project\node_modules\metro\src\lib\transformHelpers.js:271:42)
ndencies.js:571:33)
    at C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:587:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:586:33)
    at C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)
    at _next (C:\Users\User\Documents\repos\project\node_modules\metro\src\DeltaBundler\traverseDependencies.js:107:9)

To wrap it up, @Asp1re has found a solution to solve the initial Error: Unable to resolve module stream which is running the yarn add stream command.总而言之,@Asp1re 找到了解决初始Error: Unable to resolve module stream正在运行yarn add stream命令的模块 stream。

After that, another error occurred:之后又出现了一个错误:

Error: While trying to resolve module `fs` from file `C:\Users\User\Documents\repos\project\node_modules\@google-cloud\logging\build\src\utils\metadata.js`, the package `C:\Users\User\Documents\repos\project\node_modules\fs\package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`C:\Users\User\Documents\repos\project\node_modules\fs\index.js`. Indeed, none of these files exist

This should be solved by adding other extensions into the metro.config.js :这应该通过在metro.config.js中添加其他扩展来解决:

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  resolver: {
    sourceExts: ['jsx', 'js', 'ts', 'tsx'], //add here
  },
};

and installing the react-native-fs .并安装react-native-fs Make sure to update the requirements from fs to react-native-fs .确保将要求从fs更新为react-native-fs

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

相关问题 登录 Cloud Functions (Node.JS) 是异步的吗? - Is logging in Cloud Functions (Node.JS) asynchronous? 在 React Native 中加密,在 node.js 中解密 - Encrypt in React Native and decrypt in node.js HTTP 来自 Google Cloud 的 POST 功能 Node.js? - HTTP POST from Google Cloud Functions Node.js? 获取/设置谷歌云存储中的元数据 - node.js - Getting/Setting metadata in google cloud storage - node.js 我无法以编程方式使用 node.js 客户端库从 google-cloud-automl 获取 model id - I can't programmatically get the model id from google-cloud-automl with node.js client library Node.js 应用程序停止在谷歌云虚拟机中运行 - Node.js application stops running in google cloud vm Google Cloud Tasks 忽略 `dispatchDeadline`,从 node.js 调用 - Google Cloud Tasks ignoring `dispatchDeadline`, invoked from node.js 从 GKE pod 查询 Node.js 中的 Google 云 SQL 实例,云 sql 代理作为边车运行 - Query a Google cloud SQL instance in Node.js from a GKE pod with cloud sql proxy running as sidecar 使用 node.js 在谷歌云存储中上传超过 1 GB 的大数据 - Uploading large data more then 1 GB in google cloud storage with node.js 在 Google Cloud Run 中运行 Node.js mongoose 应用程序时连接过多 MongoDB - Too much MongoDB connections when running Node.js mongoose app in Google Cloud Run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM