google-api-nodejs-client
google-api-nodejs-client copied to clipboard
Errors building with webpack
#1286 and #741 suggest that this module should work with webpack. However, I'm having errors trying to build a simple webpack project.
Environment details
- OS: Ubuntu 20.04.1 LTS
- Node.js version: v14.8.0
- npm version: 6.14.8
googleapisversion: 59.0.0
Steps to reproduce
- Create the files listed below (this is the simplest example I can come up with)
- Run
npm run build - Observe webpack spitting out errors about how it can't find lots of modules
package.json:
{
"dependencies": {
"googleapis": "59.0.0"
},
"devDependencies": {
"webpack": "4.44.1",
"webpack-cli": "3.3.12"
},
"scripts": {
"dev": "webpack"
}
}
src/index.js:
import {google} from 'googleapis'
console.log(google)
Errors output by webpack:
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/workspace/bug/node_modules/google-auth-library/build/src/auth'
@ ./node_modules/google-auth-library/build/src/auth/googleauth.js 17:24-48
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'fs' in '/workspace/bug/node_modules/google-auth-library/build/src/auth'
@ ./node_modules/google-auth-library/build/src/auth/googleauth.js 18:11-24
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
etc etc
Full error output
ERROR in ./node_modules/google-p12-pem/build/src/index.js
Module not found: Error: Can't resolve 'fs' in '/workspace/bug/node_modules/google-p12-pem/build/src'
@ ./node_modules/google-p12-pem/build/src/index.js 10:11-24
@ ./node_modules/gtoken/build/src/index.js
@ ./node_modules/google-auth-library/build/src/auth/jwtclient.js
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/googleapis-common/build/src/discovery.js
Module not found: Error: Can't resolve 'fs' in '/workspace/bug/node_modules/googleapis-common/build/src'
@ ./node_modules/googleapis-common/build/src/discovery.js 16:11-24
@ ./node_modules/googleapis-common/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/gtoken/build/src/index.js
Module not found: Error: Can't resolve 'fs' in '/workspace/bug/node_modules/gtoken/build/src'
@ ./node_modules/gtoken/build/src/index.js 10:11-24
@ ./node_modules/google-auth-library/build/src/auth/jwtclient.js
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/googleapis-common/build/src/http2.js
Module not found: Error: Can't resolve 'http2' in '/workspace/bug/node_modules/googleapis-common/build/src'
@ ./node_modules/googleapis-common/build/src/http2.js 16:14-30
@ ./node_modules/googleapis-common/build/src/apirequest.js
@ ./node_modules/googleapis-common/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/https-proxy-agent/dist/agent.js
Module not found: Error: Can't resolve 'net' in '/workspace/bug/node_modules/https-proxy-agent/dist'
@ ./node_modules/https-proxy-agent/dist/agent.js 15:30-44
@ ./node_modules/https-proxy-agent/dist/index.js
@ ./node_modules/gaxios/build/src/gaxios.js
@ ./node_modules/gaxios/build/src/index.js
@ ./node_modules/google-auth-library/build/src/transporters.js
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
ERROR in ./node_modules/https-proxy-agent/dist/agent.js
Module not found: Error: Can't resolve 'tls' in '/workspace/bug/node_modules/https-proxy-agent/dist'
@ ./node_modules/https-proxy-agent/dist/agent.js 16:30-44
@ ./node_modules/https-proxy-agent/dist/index.js
@ ./node_modules/gaxios/build/src/gaxios.js
@ ./node_modules/gaxios/build/src/index.js
@ ./node_modules/google-auth-library/build/src/transporters.js
@ ./node_modules/google-auth-library/build/src/index.js
@ ./node_modules/googleapis/build/src/index.js
@ ./src/index.js
Note if like me you're not bundling for the browser you can resolve these problems by telling webpack to bundle for node by adding the following to webpack.config.js:
module.exports = {
target: 'node'
}
That works for me, however I'm leaving this ticket here because it appears there is still a problem if you are genuinely bundling to run in the browser.
Greetings, we're closing this. Looks like the issue got resolved. Please let us know if the issue needs to be reopened.
@fhinkel the issue is resolved when bundling for node, but not when bundling for the browser. I'll leave it to the project maintainers whether they'd rather have bug reports in an 'open' or 'closed' state, but afaics the issue still exists.
Any progress on this issue? It looks you might be using workspaces, and I'm having a similar problem with trying to get webpack to work with my npm 7 workspaces project
I think this was resolved by #2524, but @alexander-fenster will confirm this solution is working.
I'm still seeing this issue with Create React App
I am still seeing the issue with Nuxt 2 and Webpack 4.
Did anybody find a solution to this. The problem is still persistent if you are trying to bundle for browser.
The problem still there. I am working on web app.
my packages:
"dependencies": {
"dotenv": "^16.3.1",
"firebase": "^9.23.0",
"googleapis": "^126.0.0",
},
"devDependencies": {
"css-loader": "^6.3.0",
"html-webpack-plugin": "^5.3.2",
"style-loader": "^3.3.0",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0"
}
Is anyone working on this issue? I have same problem with react app