Angular 6:错误:安装google-translate-api后无法解析"./package" [英] Angular 6: Error: Can't resolve './package' after installing google-translate-api
问题描述
我刚刚通过npm
和npm install --save google-translate-api
安装了google-translate-api
.我没有收到任何错误消息,但是当我尝试运行npm start
时,它显示了以下错误:
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:
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'
我还读到它可能是我的package.json
中的一个sintax错误,但是我看不到任何错误.以防万一,这是我的package.json
文件:
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:
{
"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"
}
}
请注意,我正在使用Angular 6,并且没有Webpack配置文件(我已经阅读了有关该文件的几种解决方案).有人可以帮我解决这个问题吗?
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?
推荐答案
我不是Angular的专家,但是在将Ionic 3应用程序(使用TypeORM)升级到Ionic 4时遇到了同样的问题-并且从Angular 5到Angular 6.
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.
我认为问题出在某些外部库(在您的情况下可能是google-translate-api-在我的情况下显然是TypeORM),这些外部库尚未准备好"在Angular 6应用程序中使用.可以在 https://中找到更详细且可能更正确的解释. github.com/angular/angular-cli/issues/9827#issuecomment-369578814 .
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.
我首先尝试安装具有相同名称的软件包,并且在大多数情况下有帮助,但是 https://github.com/DevExpress/devextreme-angular/issues/776#issuecomment-399344876 指出,不建议这样做.
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.
更好的方法是替换最后,我仍然遇到"hiredis"(特定于TypeORM)错误:
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:\Users\Dennis\git\keep-tabs\node_modules\redis-parser\lib'
在我看来,这是可选的,因此我打开了文件,并注释了需求声明及其每次使用.
which I think is optional in my case, so I opened the file and commented out the require-statement and every use of it.
此解决方案并不令人满意,因为它需要更改node_modules文件夹中的文件,但是当前我认为这可能是在受影响的库尚未"Angular 6就绪"时使用的解决方法.
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".
关于, 丹尼斯
这篇关于Angular 6:错误:安装google-translate-api后无法解析"./package"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!