terence410 / ts-google-drive

MIT License
58 stars 7 forks source link

Error at call TsGoogleDrive constructor in angular 12 #4

Closed flaviamatdev closed 1 year ago

flaviamatdev commented 2 years ago

Hi, when I try call TsGoogleDrive constructor inside my service in angular 12, the project Failed to compile, I didn't even call the method auth anywhere!

import { Injectable } from '@angular/core';
import { TsGoogleDrive } from "ts-google-drive";

@Injectable({
    providedIn: 'root'
})
export class GDriveApiService {

    async auth() {
        const drive1 = new TsGoogleDrive({ keyFilename: "serviceAccount.json" });
        //...
    }

Errors

./node_modules/gaxios/build/src/gaxios.js:29:16-32 - Error: Module not found: Error: Can't resolve 'https' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\gaxios\build\src'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
        - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "https": false }

./node_modules/google-auth-library/build/src/auth/googleauth.js:22:24-48 - Error: Module not found: Error: Can't resolve 'child_process' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\google-auth-library\build\src\auth'

./node_modules/google-auth-library/build/src/crypto/node/crypto.js:22:15-32 - Error: Module not found: Error: Can't resolve 'crypto' in 
'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\google-auth-library\build\src\crypto\node'
Did you mean './crypto'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (F:/projetos_codigos/heroku/angular/teacher-fe, node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

./node_modules/https-proxy-agent/dist/agent.js:15:30-44 - Error: Module not found: Error: Can't resolve 'net' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\https-proxy-agent\dist'

./node_modules/https-proxy-agent/dist/agent.js:16:30-44 - Error: Module not found: Error: Can't resolve 'tls' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\https-proxy-agent\dist'

./node_modules/https-proxy-agent/dist/agent.js:18:33-50 - Error: Module not found: Error: Can't resolve 'assert' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\https-proxy-agent\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
        - install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "assert": false }

./node_modules/jwa/index.js:3:13-30 - Error: Module not found: Error: Can't resolve 'crypto' in 'F:\projetos_codigos\heroku\angular\teacher-fe\node_modules\jwa'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
        - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "crypto": false }

Project Settings

Angular CLI: 12.2.12
Node: 14.18.1 Package Manager: npm 6.14.15 OS: win32 x64 Angular: 12.2.12

my package.json

"dependencies": {
        "@angular/animations": "~12.2.0",
        "@angular/cdk": "^12.2.12",
        "@angular/common": "~12.2.0",
        "@angular/compiler": "~12.2.0",
        "@angular/core": "~12.2.0",
        "@angular/forms": "~12.2.0",
        "@angular/material": "^12.2.12",
        "@angular/platform-browser": "~12.2.0",
        "@angular/platform-browser-dynamic": "~12.2.0",
        "@angular/router": "~12.2.0",
        "@types/gapi": "0.0.41",
        "@types/gapi.auth2": "0.0.55",
        "@types/gapi.client.drive": "^3.0.13",
        "child_process": "^1.0.2",
        "colors": "^1.4.0",
        "dotenv": "^10.0.0",
        "express": "^4.17.1",
        "file-system": "^2.2.2",
        "font-awesome": "^4.7.0",
        "fs": "0.0.1-security",
        "googleapis": "^89.0.0",
        "os": "^0.1.2",
        "path": "^0.12.7",
        "rxjs": "~6.6.0",
        "stream": "0.0.2",
        "ts-google-drive": "0.0.6",
        "tslib": "^2.3.0",
        "util": "^0.12.4",
        "zone.js": "~0.11.4"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "^12.2.12",
        "@angular/cli": "~12.2.11",
        "@angular/compiler-cli": "~12.2.0",
        "@types/jasmine": "~3.8.0",
        "@types/node": "^12.20.36",
        "buffer": "^6.0.3",
        "jasmine-core": "~3.8.0",
        "karma": "~6.3.0",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage": "~2.0.3",
        "karma-jasmine": "~4.0.0",
        "karma-jasmine-html-reporter": "~1.7.0",
        "process": "^0.11.10",
        "typescript": "~4.3.5"
    },
terence410 commented 2 years ago

I didn't intended to make the library works for web. But I will try to solve it out for you as well. I will take a look and let you know, stay focus~

vishnushankar-hub commented 2 years ago

Is this issue fixed yet ?

terence410 commented 1 year ago

this can't be run in the web

terence410 commented 1 year ago

try to setup a server and prepare API to be called from your client side