gpt4 book ai didi

node.js - 将 google-cloud 与 webpack 集成时出现问题

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:36 25 4
gpt4 key购买 nike

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

我遇到的错误-

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

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

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

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

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

谁能帮我解决这个问题?

最佳答案

我看到您正在使用 webpack,我假设您正在后端使用 google-cloud 库。

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

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

解释

用于后端的模块并不是真正为了将它们捆绑在一起而制作的(参见:Backend Apps with Webpack)。所以我们使用 webpack 的 externals 配置来排除那些不能很好地处理捆绑的库。当应用程序运行时,它们只是像往常一样从 node_modules 目录中 require()

如果你不想一个一个地指定你的违规模块,试试webpack-node-externals自动排除所有模块。

关于node.js - 将 google-cloud 与 webpack 集成时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42920761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com