question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am getting error just after importing @google-cloud/storage : Module not found: Error can't resolve 'child_process', how to fix?

See original GitHub issue

I am getting error just after importing @google-cloud/storage

Environment details

  • OS: macOS Big Sur
  • Node.js version: v12.18.4
  • npm version:6.14.6
  • @google-cloud/storage version:^ 5.6.0
  • framework nuxt js version : Nuxt.js @ v2.14.7

Steps to reproduce

  1. install @google-cloud/storage yarn add @google-cloud/storageor npm install @google-cloud/storage --save
  2. import it const {Storage} = require(‘@google-cloud/storage’); const storage = new Storage({ keyFilename : path.join(__dirname, ‘./file.json’), projectId: “xxx-xxx-xxx” });

just after that i got this error

ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js Module not found: Error: Can't resolve 'child_process' in '/Users/xxx/xxxx/node_modules/google-auth-library/build/src/auth' ERROR in ./node_modules/@google-cloud/storage/build/src/file.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/@google-cloud/storage/build/src' ERROR in ./node_modules/@google-cloud/storage/build/src/bucket.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/@google-cloud/storage/build/src' ERROR in ./node_modules/configstore/node_modules/make-dir/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/configstore/node_modules/make-dir' ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/google-auth-library/build/src/auth' ERROR in ./node_modules/google-p12-pem/build/src/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/google-p12-pem/build/src' ERROR in ./node_modules/graceful-fs/graceful-fs.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/graceful-fs' ERROR in ./node_modules/gtoken/build/src/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/gtoken/build/src' ERROR in ./node_modules/write-file-atomic/index.js Module not found: Error: Can't resolve 'fs' in '/Users/xxx/xxxx/node_modules/write-file-atomic' ERROR in ./node_modules/http-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'net' in '/Users/xxx/xxxx/node_modules/http-proxy-agent/dist' ERROR in ./node_modules/https-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'net' in '/Users/xxx/xxxx/node_modules/https-proxy-agent/dist' ERROR in ./node_modules/http-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'tls' in '/Users/xxx/xxxx/node_modules/http-proxy-agent/dist' ERROR in ./node_modules/https-proxy-agent/dist/agent.js Module not found: Error: Can't resolve 'tls' in '/Users/xxx/xxxx/node_modules/https-proxy-agent/dist' Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
alexander-fenstercommented, Jan 23, 2021

This sounds like a fun thing with Nuxt that wants to use Webpack bundle even when running on the server side. I found https://github.com/nuxt-community/dotenv-module/issues/11 which suggested that we could blocklist some Node modules for webpack, and they will magically start working on the Node side of the things. Try this in your nuxt.config.js:

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    extend (config, ctx) {
        config.node = {
            fs: "empty",
            child_process: "empty",
            net: "empty",
            tls: "empty"
        };
    }
  }

My pages/index.vue that worked:

<script>
const storage = require('@google-cloud/storage');
console.log(storage);
// exports and other stuff here
</script>

Note: we have never tested this library with Nuxt. Consider this to be a “warranty void if seal broken” situation - let us know if anything does not work but fixing stuff might be complicated.

2reactions
Segrelovecommented, Dec 14, 2020

I’m having the same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

i am getting error while importing @google-cloud/storage
the problem you are using @google-cloud/storage on client side code, this lib is supposed to be used on server side only.
Read more >
Authenticating users with Node.js - Google Cloud
This tutorial uses the following billable components of Google Cloud: ... This app doesn't store any data; it just echoes it back to...
Read more >
google-auth-library - npm
This is Google's officially supported node.js client library for using OAuth 2.0 authorization and authentication with Google APIs. A ...
Read more >
Importing Timestamp from @google-cloud/firebase breaks app
node_modules/google-auth-library/build/src/auth/googleauth.js Module not found: Error: Can't resolve 'child_process' in ...
Read more >
Announcing an Open-Source Scouting App - #20 by Mr.R_2 ...
In order to fix the error above, I needed to log into firebase through the ... Error: Module not found: Error: Can't resolve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found