palash-kulkarni
palash-kulkarni

Reputation: 407

Getting an issue while integrating google-cloud with webpack

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

Errors i am encountering -

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

Can anybody help me to resolve this?

Upvotes: 8

Views: 4346

Answers (1)

Chris
Chris

Reputation: 2290

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

Try putting this in your webpack config:

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

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.

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

Upvotes: 16

Related Questions