Angular 6:错误:Can't resolve './package'安装 google-translate-api 后 [英] Angular 6: Error: Can't resolve './package' after installing google-translate-api

查看:62
本文介绍了Angular 6:错误:Can't resolve './package'安装 google-translate-api 后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚通过 npmnpm 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 中的语法错误,但我没有发现任何错误.以防万一,这是我的 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://https://github.com/angular/angular-cli/issues/9827#issuecomment-369578814" rel="nofollow noreferrer">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.

更好的方法是替换 node_modules/@angular-devkit 中的文件,该文件在 https://github.com/stellar/js-stellar-base/issues/128#issuecomment-391374590.

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.

最后,我仍然遇到了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'

我认为在我的情况下这是可选的,所以我打开了文件并注释掉了 require 语句和它的每次使用.

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:错误:Can't resolve './package'安装 google-translate-api 后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆