Angular 6: Error: Can't resolve './package' after installing google-translate-api

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Angular 6: Error: Can't resolve './package' after installing google-translate-api



I've just installed google-translate-api via npm with npm install --save google-translate-api. I didn't get any error message, but when I tried to run npm start it showed the following errors:


google-translate-api


npm


npm install --save google-translate-api


npm start


ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve './package' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/got'
ERROR in ./node_modules/osenv/osenv.js
Module not found: Error: Can't resolve 'child_process' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/osenv'
ERROR in ./node_modules/graceful-fs/polyfills.js
Module not found: Error: Can't resolve 'constants' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/graceful-fs'
ERROR in ./node_modules/graceful-fs/fs.js
Module not found: Error: Can't resolve 'fs' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/graceful-fs'
ERROR in ./node_modules/graceful-fs/graceful-fs.js
Module not found: Error: Can't resolve 'fs' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/graceful-fs'
ERROR in ./node_modules/mkdirp/index.js
Module not found: Error: Can't resolve 'fs' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/mkdirp'
ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'http' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/got'
ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'https' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/got'
ERROR in ./node_modules/os-homedir/index.js
Module not found: Error: Can't resolve 'os' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/os-homedir'
ERROR in ./node_modules/configstore/index.js
Module not found: Error: Can't resolve 'path' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/configstore'
ERROR in ./node_modules/mkdirp/index.js
Module not found: Error: Can't resolve 'path' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/mkdirp'
ERROR in ./node_modules/osenv/osenv.js
Module not found: Error: Can't resolve 'path' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/osenv'
ERROR in ./node_modules/xdg-basedir/index.js
Module not found: Error: Can't resolve 'path' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/xdg-basedir'
ERROR in ./node_modules/duplexer3/index.js
Module not found: Error: Can't resolve 'stream' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/duplexer3'
ERROR in ./node_modules/get-stream/buffer-stream.js
Module not found: Error: Can't resolve 'stream' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/get-stream'
ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'stream' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/got'
ERROR in ./node_modules/graceful-fs/legacy-streams.js
Module not found: Error: Can't resolve 'stream' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/graceful-fs'
ERROR in ./node_modules/safe-eval/index.js
Module not found: Error: Can't resolve 'vm' in '/home/zolastro/Documents/Work/GenEnginePMV/genengine/GenEngine/node_modules/safe-eval'



I've also read that it might be a sintax error in my package.json, but I don't see anything wrong there. Just in case, here it is my package.json file:


package.json


package.json



"name": "gen-engine-web-app",
"version": "0.0.0",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
,
"private": true,
"dependencies":
"@angular/animations": "^6.0.3",
"@angular/cdk": "^6.2.0",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/material": "^6.2.0",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"@ng-select/ng-select": "^2.1.3",
"angular-font-awesome": "^3.1.2",
"angularfire2": "^5.0.0-rc.10",
"core-js": "^2.5.4",
"firebase": "^5.0.4",
"font-awesome": "^4.7.0",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.2.0",
"zone.js": "^0.8.26"
,
"devDependencies":
"@angular-devkit/build-angular": "~0.6.6",
"@angular/cli": "~6.0.7",
"@angular/compiler-cli": "^6.0.3",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^2.0.2",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"




Please, notice that I'm using Angular 6 and there isn't a Webpack configuration file (I've read several solutions regarding that file). Could anyone help me to solve this?




1 Answer
1



I'm far from being an expert in Angular, but I ran into the same issue while upgrading my Ionic 3 application (using TypeORM) to Ionic 4 - and with it from Angular 5 to Angular 6.



I think the problem is with some external libraries (in your case it might be google-translate-api - in my case obviously TypeORM) which are not "ready" to be used in Angular 6 applications. A more detailed and probably more correct explanation can be found in https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814.



I first tried to install packages having the same name and it helped in most cases, but as https://github.com/DevExpress/devextreme-angular/issues/776#issuecomment-399344876 states, this is not recommended.



A better way is to replace a file in node_modules/@angular-devkit which is described in https://github.com/stellar/js-stellar-base/issues/128#issuecomment-391374590.



Finally, I had still an error with "hiredis" (specific to TypeORM):


ERROR in ./node_modules/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in 'C:UsersDennisgitkeep-tabsnode_modulesredis-parserlib'



which I think is optional in my case, so I opened the file and commented out the require-statement and every use of it.



This solution is not satisfying as it requires to change files in the node_modules folder but currently I think this may be the workaround to use while the affected libraries are not "Angular 6 ready".



Regards,
Dennis





Thanks for answering, but as you said, I don't think this is the recommended way to do it. I'll just wait for now, I don't have any deadlines yet!
– Antonio David Ponce Martínez
Aug 14 at 8:09







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard