将 google-cloud 与 webpack 集成时遇到问题 [英] Getting an issue while integrating google-cloud with webpack

查看:24
本文介绍了将 google-cloud 与 webpack 集成时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 google-cloud npm 包与我的 React 应用程序集成,并且我正在使用 firebase.

I am integrating the google-cloud npm package with my react application and i am using firebase.

我遇到的错误 -

./~/google-cloud/~/hash-stream-validation/index.js 模块中的警告未找到:错误:无法解析fast-crc32c"'/home/linuxbox/React-Workspace/Kaptify/node_modules/google-cloud/node_modules/hash-stream-validation'@ ./~/google-cloud/~/hash-stream-validation/index.js 5:8-30 @./~/google-cloud/~/@google-cloud/storage/src/file.js @./~/google-cloud/~/@google-cloud/storage/src/index.js @./~/google-cloud/src/index.js @ ./src/actions/UserStateStore.js @./app.js @ multi (webpack)-dev-server/client?http://127.0.0.1:3000webpack/hot/dev-server ./app.js

WARNING in ./~/google-cloud/~/hash-stream-validation/index.js Module not found: Error: Can't resolve 'fast-crc32c' in '/home/linuxbox/React-Workspace/Kaptify/node_modules/google-cloud/node_modules/hash-stream-validation' @ ./~/google-cloud/~/hash-stream-validation/index.js 5:8-30 @ ./~/google-cloud/~/@google-cloud/storage/src/file.js @ ./~/google-cloud/~/@google-cloud/storage/src/index.js @ ./~/google-cloud/src/index.js @ ./src/actions/UserStateStore.js @ ./app.js @ multi (webpack)-dev-server/client?http://127.0.0.1:3000 webpack/hot/dev-server ./app.js

./~/google-cloud/~/google-auto-auth/index.js 中的警告 53:13-58关键依赖:一个依赖的请求是一个表达式

WARNING in ./~/google-cloud/~/google-auto-auth/index.js 53:13-58 Critical dependency: the request of a dependency is an expression

./~/google-cloud/~/grpc/src/node/src/grpc_extension.js 中的警告38:14-35 关键依赖:依赖的请求是一个表达

WARNING in ./~/google-cloud/~/grpc/src/node/src/grpc_extension.js 38:14-35 Critical dependency: the request of a dependency is an expression

./~/google-cloud/~/node-pre-gyp/lib/pre-binding.js 中的警告 19:22-48关键依赖:一个依赖的请求是一个表达式

WARNING in ./~/google-cloud/~/node-pre-gyp/lib/pre-binding.js 19:22-48 Critical dependency: the request of a dependency is an expression

./~/google-cloud/~/node-pre-gyp/lib/util/versioning.js 中的警告15:20-67 关键依赖:依赖的请求是一个表达

WARNING in ./~/google-cloud/~/node-pre-gyp/lib/util/versioning.js 15:20-67 Critical dependency: the request of a dependency is an expression

有人能帮我解决这个问题吗?

Can anybody help me to resolve this?

推荐答案

我看到你在使用 webpack,我假设你在后端使用 google-cloud 库.

I see you're using webpack, and I'm assuming you're using the google-cloud library in the backend.

尝试将其放入您的 webpack 配置中:

Try putting this in your webpack config:

config = {
    // ...
    externals: {
        '@google-cloud/storage': 'commonjs @google-cloud/storage'
    },
    // ...
}

说明

用于后端的模块实际上并不是为了捆绑它们而制作的(请参阅:Webpack 后端应用).所以我们使用 webpack 的 externals 配置来排除不能很好地处理这种捆绑的库.当应用程序运行时,它们只是像平常一样从 node_modules 目录中require()'ed.

Explanation

Modules meant for the backend aren't really made with the intention of them being bundled (see: Backend Apps with Webpack). So we use webpack's externals config to exclude libraries that don't handle that bundling well. When the app is run, they are just require()'ed from the node_modules directory as normal.

如果您不想一一指定有问题的模块,请尝试使用 webpack-node-externals 自动排除所有模块.

If you don't want to specify your offending modules one-by-one, try out webpack-node-externals to automatically exclude all modules.

这篇关于将 google-cloud 与 webpack 集成时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆