typescript 您似乎并不依赖“@angular/core”。打字稿

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46452956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:56:16  来源:igfitidea点击:

You seem to not be depending on "@angular/core". Typescript

node.jsangulartypescriptnpme2e-testing

提问by danio900409

I'm trying to run a command at npm start, but I get the message: "You seem to be not dependent on" @angular/core ". This is an error. What could be the reason? As it writes in the console: npm @angular/core -v it gets 5.4.2

我试图在 npm start 上运行一个命令,但我收到消息:“你似乎不依赖于”@angular/core“。这是一个错误。可能是什么原因?正如它在控制台中所写的那样: npm @angular/core -v 它得到 5.4.2

My package.json

我的 package.json

"dependencies": {
"@angular/animations": "^4.4.3",
"@angular/common": "^4.4.3",
"@angular/compiler": "^4.4.3",
"@angular/core": "^4.4.3",
"@angular/forms": "^4.4.3",
"@angular/http": "^4.4.3",
"@angular/platform-browser": "^4.4.3",
"@angular/platform-browser-dynamic": "^4.4.3",
"@angular/router": "^4.4.3",
"applicationinsights-js": "^1.0.12",
"core-js": "^2.4.1",
"date-fns": "^1.28.5",
"deepmerge": "^1.5.1",
"fingerprintjs2": "^1.5.1",
"ng2-page-scroll": "^4.0.0-beta.9",
"ngx-mydatepicker": "2.1.2",
"rxjs": "^5.1.0",
"zone.js": "^0.8.12"
},
"devDependencies": {
"@angular/cli": "^1.4.2",
"@angular/compiler-cli": "^4.4.3",
"@angular/language-service": "^4.4.3",
"@types/applicationinsights-js": "^1.0.4",
"@types/deepmerge": "^1.3.2",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"gulp": "^3.9.1",
"gulp-deploy-git": "^0.5.3",
"gulp-replace": "^0.6.1",
"husky": "^0.14.3",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"lint-staged": "^4.0.3",
"prettier": "^1.5.3",
"protractor": "^5.1.2",
"run-sequence": "^2.1.0",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "^2.5.2"
}

回答by fiza khan

I encountered the same issue to resolve this all you need to do is to

我遇到了同样的问题来解决这个问题,你需要做的就是

cd <project_name>

and then run the following command:

然后运行以下命令:

npm update

and than the project will be succesfully compiled.

然后项目将成功编译。

回答by Sunil Kumar Sahu

I have also faced the same issue while executing below command.

在执行以下命令时,我也遇到了同样的问题。

D:\My_Project>ng serve

Then I have followed below steps and it worked for me.

然后我按照以下步骤操作,它对我有用。

D:\My_Project>npm link
D:\My_Project>ng serve

Keep trying, good luck :)

继续努力,祝你好运:)

回答by Bartek Cichocki

Try to remove node_modulesfolder, package-lock.jsonfile and then run:

尝试删除node_modules文件夹,package-lock.json文件,然后运行:

npm cache clean --force
npm cache verify
npm i

回答by Ananthi R

This error occurred in my case when my node_modules folder is empty otherwise it will have bunch of folders inside. I used the "ng link" command to work it out.

当我的 node_modules 文件夹为空时,就会发生此错误,否则里面会有一堆文件夹。我使用“ng link”命令来解决它。

My project name is Pipes, and my command prompt looks like this:

我的项目名称是 Pipes,我的命令提示符如下所示:

Pipes$ npm link

管道 $ npm 链接

And finally you can execute ng serve to check it out

最后你可以执行 ng serve 来检查它

回答by Kunvar Singh

You need to remove ^this, because something its get that version where the others files are effecting due to this version,

你需要删除^这个,因为它得到了那个版本,其他文件由于这个版本而影响,

so always use the specific version in angular.

所以总是在 angular 中使用特定的版本。

or you can use the following package.json here:

或者您可以在此处使用以下 package.json:

{
  "name": "artist-booking-app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "4.0.0",
    "@angular/common": "4.0.0",
    "@angular/compiler": "4.0.0",
    "@angular/core": "4.0.0",
    "@angular/forms": "4.0.0",
    "@angular/http": "4.0.0",
    "@angular/platform-browser": "4.0.0",
    "@angular/platform-browser-dynamic": "4.0.0",
    "@angular/router": "4.0.0",
    "angular2-toaster": "^4.0.1",
    "bootstrap": "3.3.7",
    "core-js": "2.4.1",
    "jquery": "3.2.1",
    "ng2-scroll-to-el": "^1.0.0",

    "primeng": "^4.1.3",
    "rxjs": "5.4.1",
    "zone.js": "0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.2.6",
    "@angular/compiler-cli": "4.0.0",
    "@angular/language-service": "4.0.0",
    "@types/jasmine": "2.5.53",
    "@types/jasminewd2": "2.0.2",
    "@types/node": "6.0.60",
    "codelyzer": "3.0.1",
    "jasmine-core": "2.6.2",
    "jasmine-spec-reporter": "4.1.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "2.1.1",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.2.1",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "3.0.4",
    "tslint": "5.3.2",
    "typescript": "2.3.3"
  }
}