关于node.js:在将google-cloud与webpack集成时遇到问题

Getting an issue while integrating google-cloud with webpack

我正在将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配置中:

1
2
3
4
5
6
7
config = {
    // ...
    externals: {
        '@google-cloud/storage': 'commonjs @google-cloud/storage'
    },
    // ...
}

解释

用于后端的模块并不是真正为了捆绑在一起而设计的(请参阅:带有Webpack的后端应用程序)。因此,我们使用webpack的externals配置来排除不能很好地解决捆绑问题的库。当应用程序运行时,它们只是从node_modules目录中进行require()修改。

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