" @ angular / compiler-cli"包没有正确安装

时间:2017-04-11 16:10:03

标签: angular angular-cli

使用 Angular CLI 1.0 (来自beta.31)将我的项目升级到 Angular 4.0 (来自2.4),在{{3}之后收到以下错误}:

> ng build --prod

The "@angular/compiler-cli" package was not properly installed.
Error: The "@angular/compiler-cli" package was not properly installed.
    at Object.<anonymous> (/home/jan/src/fm-repos/fm-ui/node_modules/@ngtools/webpack/src/index.js:14:11)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/jan/src/fm-repos/fm-ui/node_modules/@angular/cli/tasks/eject.js:10:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

迁移后我的角度依赖关系:

"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^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",
"@angular/cli": "1.0.0",
"@angular/material": "2.0.0-beta.3",

注意:这个类似的问题是关于 Angular 2 项目:migration guide

10 个答案:

答案 0 :(得分:9)

确保package.json中包含 TypeScript 2.2 ,并确保 tsconfig 已正确更新。

<强>详情:

安装Angular CLI 1.0后,创建一个新的虚拟项目:

ng new dummy

然后删除node_modules目录:

rm -rf ./dummy/node_modules
rm -rf ./myproject/node_modules

diff dummy项目与项目之间的变化:

diff -bur ./dummy/ ./myproject/

在许多更改中,为我解决此错误所需的关键更改是TypeScript和tsconfig更改:

<强> package.json

"typescript": "~2.0.3" ==> "typescript": "~2.2.0"

<强> .angular-cli.json

变化:

"tsconfig": "tsconfig.json"

为:

"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",

并从dummy项目中添加这些新文件,然后安装您的软件包:

npm install

答案 1 :(得分:8)

我在Linux机器上创建新的全新安装     _ _ ____ _ _    / \ _ __ __ _ _ _ | | __ _ _ __ / | | | |   /△\ | &#39; \ / _ | | | | |/ _ | &#39;的 | | | | | | |  / \ | | | | ( | | | | | |( | | | | | | | | | / / __ | | | __,| __, | | __, | | ____ | _____ | |                | / @ angular / cli:1.0.1 节点:6.10.2 os:linux x64

我正在使用

创建新的角度2项目

ng new angularhellword

项目已成功创建,但是当我执行命令

ng serve

鉴于我上面的错误,如

  

&#34; @ angular / compiler-cli&#34;包没有正确安装。

请采取以下步骤以避免问题:

&#34; npm uninstall --save-dev angular-cli&#34;

&#34; npm install --save-dev @ angular / cli @ latest&#34;

它适用于我,项目运行成功。

答案 2 :(得分:2)

npm uninstall -g angular-cli
rm -rf ./node_modules
rm package-lock.json
npm install --save-dev @angular/cli@latest

如果安装最新版本仍然会出现错误,您可以再次执行卸载过程,并在验证angular-cli repo中的最新版本后手动输入angular-cli的版本。我的package.json列出了^ 1.3.0,但是有一个beta版本刚刚发布,当我手动将其更改为

"@angular/cli": "^1.3.0-beta.0"    
npm i

已成功安装

答案 3 :(得分:1)

对我而言,上述解决方案均无效,但全局更新npm和打字稿。

要更新,请运行以下命令:

npm update

npm update -g typescript

答案 4 :(得分:0)

当我在设置Angular 2时运行OS 10.12.4时,我的Mac上也出现了同样的错误消息。

我在两台不同的Windows 10机器上也遇到了类似的问题。 Windows机器收到错误,

    Node_modules appears empty, you may need to run `npm install`.

在这两种情况下,我都可以通过在项目目录中运行npm install来解决问题。

我进入了命令行/终端,然后进入了存储项目的目录,例如:

    c:\Users\myname\projectname>

对于Windows,我使用了npm install命令,而在Mac中,我使用了sudo npm install

在这两种情况下都解决了这个问题。

答案 5 :(得分:0)

我尝试了一切,对我有用的唯一一件事就是简单 npm install

答案 6 :(得分:0)

打开package.json并在依赖项下移动@angular/cli,如:

"dependencies": {
    "@angular/animations": "^4.0.0",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/cli": "1.2.1",
    "@angular/compiler-cli": "^4.3.1",
    "@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",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },

然后在命令提示符下转到项目文件夹并运行命令&#34; npm install&#34;。它将加载所有必要的依赖项。

答案 7 :(得分:0)

我刚刚改为&#34; @ angular / compiler-cli&#34;:&#34; ^ 4.3.2&#34;来自&#34; @ angular / compiler-cli&#34;:&#34; ^ 4.0.0&#34;在package.json文件中的devDependencies中。

它对我有用

答案 8 :(得分:0)

这就像魔术一样

  

npm install --save-dev del

答案 9 :(得分:0)

请尝试以下步骤: 清理

remove node_modules from your project
remove any angular-cli and @angular/cli references from package.json if it's there
Uninstall angular-cli and @angular/cli globally: npm uninstall -g angular-cli @angular/cli

重新安装

Install @angular/cli globally: npm install -g @angular/cli
Install @angular/cli in your project: npm install --save-dev @angular/cli