8

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?

palash-kulkarni
  • 397
  • 3
  • 17
  • Do you use `google-cloud` in frontend code or backend code? If it's frontend, you probably want to use this library: https://developers.google.com/api-client-library/javascript/start/start-js – Chris Jun 09 '17 at 03:25

1 Answers1

16

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.

Chris
  • 2,174
  • 28
  • 37
  • 2
    How does this solve the issue? When you take the webpacked javascript elsewhere it won't work due to missing modules – Oded Niv Mar 10 '19 at 15:58
  • @OdedNiv If you do this for a library you're making, you'll need to have the packages you exclude listed in `dependencies` in `package.json` so anything consuming your library also downloads the necessary modules. – Chris Mar 14 '19 at 09:15
  • He says he is integrating google-cloud with his "react application", which is the opposite of a library – Oded Niv Mar 15 '19 at 10:34