[英]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/logging
和yarn 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.