Validate it works with react-native
Please add child_process module to package.json
Or better remove all deps in code
@airstep child_process is a Node.js built-in module. It should not be added to package.json as it doesn't need to be fetched from npm.
Can you elaborate on what you mean by Or better remove all deps in code?
I just trying to use google-cloud/storage in ionic project wich depends on google-auth-librarary and get error: Cannot find module "child_process"
Can you please share some sample code, and the full callstack?
I am going to close this issue. Feel free to re-open the issue if this is still a question, and once the necessary information is available.
I've encountered an issue with child_process as well. Using a fresh build of create-react-app:
Failed to compile
Failed to compile
./~/google-auth-library/lib/auth/googleauth.js
Module not found: Can't resolve 'child_process' in 'D:\Projects\LeagueDecay\node_modules\google-auth-library\lib\auth'
Stack:
04:20:27.944 ./~/google-auth-library/lib/auth/googleauth.js
Module not found: Can't resolve 'child_process' in 'D:\Projects\TestProject\node_modules\google-auth-library\lib\auth' 1 bundle.js:30424:16
__stack_frame_overlay_proxy_console__ http://localhost:3000/static/js/bundle.js:30424:16
handleErrors http://localhost:3000/static/js/bundle.js:12206:7
./node_modules/react-dev-utils/webpackHotDevClient.js/connection.onmessage http://localhost:3000/static/js/bundle.js:12239:7
./node_modules/sockjs-client/lib/event/eventtarget.js/EventTarget.prototype.dispatchEvent http://localhost:3000/static/js/bundle.js:36232:5
./node_modules/sockjs-client/lib/main.js/</SockJS.prototype._transportMessage/< http://localhost:3000/static/js/bundle.js:37030:11
./node_modules/sockjs-client/lib/main.js/</SockJS.prototype._transportMessage http://localhost:3000/static/js/bundle.js:37028:9
./node_modules/sockjs-client/lib/event/emitter.js/EventEmitter.prototype.emit http://localhost:3000/static/js/bundle.js:36126:5
WebSocketTransport/this.ws.onmessage http://localhost:3000/static/js/bundle.js:39326:5
Please reopen this issue, I got the same problem. Failed to compile.
./~/google-auth-library/lib/auth/googleauth.js Module not found: Can't resolve 'child_process' in '/Users/kevinzhang/github/formAddOn/google_form_addon/developer/react-app/node_modules/google-auth-library/lib/auth'
@MauriceMahan @kevingzhang Correct me if I'm wrong, but it looks like you're running or transpiling code that is meant to run on the client-side. child_process (and other built-in node modules) won't be available in this scenario, and I don't think this library would work in the browser as a result.
This document might point you in the right direction.
Thank @kjin shortly after I post my message, I realized that you mis used my existing code which was originally running on server end but now from front end. You are right, it is my mistake. In this case, I cannot reuse my existing backend code, need to write some new code. Thank you very much. Your answer is right.
This dependency was not found:
- child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js
To install it, you can run: npm install --save child_process
Listening at http://localhost:8080
how to resolve this error
I have the same problem.
When I try to import firebase-auth I get:
ERROR Failed to compile with 38 errors
These dependencies were not found:
* child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.
js, ./node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
* fs in ./node_modules/@google-cloud/storage/src/file.js, ./node_modules/@google
-cloud/storage/src/bucket.js and 34 others
To install them, you can run: npm install --save child_process fs
Of course I've tried to install those deps, but with no results.
I was experiencing this issue when trying to load server-only stuff into client side. Solved now.
Adding
node: { child_process: 'empty' } to webpack config file and the error is gone. Not sure how it works, It seems like webpack did some thing with child_process module in web target.
Using this library with server-less next.js, I was able to get my code to build by adding the following to my webpack config in next.config.js:
node: {
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
...config.node,
fs: 'empty',
child_process : 'empty',
net : 'empty',
tls: 'empty',
}
child_process could easily be wrapped in a require() call in the function it's used, to prevent automatic failure in environments like react-native. I have to fork this to get it to work there.
Seems the webpack build doesn't properly empty child_process and it's still being required in the built assets.
For anyone else trying to use this library on react-native, ~~I've forked it.~~ I've re-written just the OAuth2 portion of this library (and with minimal functionality reproduction) here.
Heh woah! What specific change do you need to make here? Instead of a fork, a patch would be looooovely :)
Well to be honest I’m still trying to get it to work. The child_process issue was just one problem and it seems as though there are more issues the further I dig.
I’m not super familiar with typescript and inlining the child_process call raises a number of type errors so I’m not sure if that’s the best way to go about it. It’d be great to get webpack to actually stub the module - maybe I’ll try this tomorrow 🧐
If I find a simple solution I’ll make a PR 👍
Out of curiosity - can you share what y'all are exactly trying to do? Most of the flows in this library make sense on the back end, but not a ton of them make sense on the front end. Just to make sure we're trying and testing the right stuff - tell me about what you're trying to do!
Ok - so I actually went and tried all this stuff myself :) Turns out ... with [email protected], this seems to "work on my machine". With no changes, I was able to create an OAuth2Client, generate an auth url, redirect back, set the tokens, and get an authorization header. Our webpack.config.js we ship (which I have no idea how or if this works out of the box with react) already excludes child_process, because you wouldn't be able to use any of that stuff in the browser anyway.
For any folks who are struggling here - can you please make to sure:
a.) use the latest blazin hot version of google-auth-library
b.) share the exact error you're getting
c.) share the exact code where you're blowin up