Foo*_*azz 49 angular-cli angular
我正在开展一个Angular 2项目.现在尝试使用以下方法在当前项目中安装Angular CLI
npm install --save-dev @angular/cli@latest
npm install
Run Code Online (Sandbox Code Playgroud)
问题是在运行时ng serve我收到错误
The "@angular/compiler-cli" package was not properly installed.
Error: The "@angular/compiler-cli" package was not properly installed.
at Object.<anonymous> (/myng2project/node_modules/@ngtools/webpack/src/index.js:14:11)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/myng2project/node_modules/@angular/cli/tasks/eject.js:10:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
Run Code Online (Sandbox Code Playgroud)
ruz*_*ack 58
我有同样的问题.我在npm @ angular/cli页面中的"更新Angular CLI"过程后解决了这个问题,即:
rm -rf node_modules dist
npm uninstall -g @angular/cli
npm cache clean
Run Code Online (Sandbox Code Playgroud)
npm install -g @angular/cli@latest
npm install
ng serve
Run Code Online (Sandbox Code Playgroud)
这对我有用.
LOT*_*SMS 23
我已经尝试了这些答案中的所有内容,唯一对我有用的是:
第1步:npm install -g @ angular/cli @ latest
第2步:输入新的项目名称(忽略项目是否已创建)
步骤3:cd项目名称(忽略项目是否已创建)
步骤4:npm install @ angular/cli --save-dev
步骤5:npm install @ angular/compiler-cli --save-dev
步骤6:ng服务
在两个不同的环境中测试了这些步骤
在项目文件夹里面,输入"npm install"并等待安装完成,这个修复程序对我来说很好.
小智 19
版本存在问题
"@angular/cli": "1.0.0-rc.4"
Run Code Online (Sandbox Code Playgroud)
尝试安装较旧的
"@angular/cli": "1.0.0-rc.2"
Run Code Online (Sandbox Code Playgroud)
这绝对是糟透了.为了让我解决它,我不得不做一些事情......
为了解决这个@angular/compiler-cli was not installed correctly错误,我不得不采用@ Ruzenhack的解决方案,即删除全局和本地@angular/cli包:
rm -rf node_modules dist
npm uninstall -g @angular/cli
npm cache clean
Run Code Online (Sandbox Code Playgroud)
但是进一步采取他的建议给@angular/cli@latest我留下了同样的问题,这导致我@ SergeyV建议我降级到旧的版本cli.就个人而言,我有另一个项目,是有工作@angular/cli@1.0.0-rc.1,所以我决定使用和在全球范围内我安装以及package.json.
成功.
但 ......
然后给了我另一个错误....
Cannot read property 'Private' of undefined
该死.
所以我从angular-cli github问题中得到了这个建议,这是为了升级我的打字稿.所以,把我的打字稿版本投入^2.0.0使用package.json,我接受了熟悉且无挫折的绿色ng serve输出.最后.
我希望这可以帮助别人.
我花了10个小时进行调查才能找到以下内容:
npm开始
总而言之,让您比较一下您的调查方法:
经过多次尝试失败后,我重新安装了节点和npm,现在我有了:
c:\> ng -v
@angular/cli: 1.3.0
node: 6.9.0
os: win32 ia32
Run Code Online (Sandbox Code Playgroud)
一切适用于新项目
ng new my-new-project
Run Code Online (Sandbox Code Playgroud)
但是我有一个妥协的项目表明
Unable to find "@angular/cli" in devDependencies.
Please take the following steps to avoid issues:
"npm install --save-dev @angular/cli@latest"
The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler-cli'
Error: The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler-cli'
at Object.<anonymous> (C:\Users\profimedica\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\index.js:14:11)
Run Code Online (Sandbox Code Playgroud)
因为我已经在全局安装了@ angular / cli,所以我只需要将其添加到package.json文件中,例如,使用新创建的项目中运行正常的相同文件:
{
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"http": "0.0.0"
},
"devDependencies": {
"@angular/cli": "1.3.0",
"@angular/compiler-cli": "^4.2.4"
}
}
Run Code Online (Sandbox Code Playgroud)
从这里引发第二个错误,因为@ angular / compiler-cli模块未作为本地模块安装:
// Check that Angular is available.
try {
version = require('@angular/compiler-cli').VERSION;
}
catch (e) {
throw new Error('The "@angular/compiler-cli" package was not properly installed. Error: ' + e);
}
Run Code Online (Sandbox Code Playgroud)
我检查了node_modules文件夹,发现文件夹。\ node_modules \ @angular \ compiler-cli,。\ node_modules \ @angular \ compiler和。\ node_modules \ @angular \ core丢失了。
我按要求安装了:
npm install @angular/compiler-cli
npm install @angular/compiler
npm install @angular/core
Run Code Online (Sandbox Code Playgroud)
我在文件中添加了日志,安装后看到了检测到的版本:。\ node_modules \ @ngtools \ webpack \ src \ index.js
console.log(require('@angular/compiler-cli').VERSION);
Version { full: '4.3.5' }
Run Code Online (Sandbox Code Playgroud)
现在我得到一个新的错误:
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (C:\PRO\htdocs\my\api\gen\projects\generated\testknowledge\node_modules\@angular\cli\tasks\serve.js:23:63)
Run Code Online (Sandbox Code Playgroud)
为了调查这个新问题,我在。\ node_modules \ @angular \ cli \ models \ config \ config.js中添加了一条日志行
class CliConfig {
constructor(_configPath, schema, configJson, fallbacks = []) {
this._configPath = _configPath;
console.log(_configPath);
this._config = new (json_schema_1.SchemaClassFactory(schema))(configJson, ...fallbacks);
}
Run Code Online (Sandbox Code Playgroud)
我得到了意想不到的价值:
C:\Users\profimedica\.angular-cli.json
Run Code Online (Sandbox Code Playgroud)
显然,此文件不在我的主目录中,而不是在项目的根目录中:
.\angular-cli.json
Run Code Online (Sandbox Code Playgroud)
经过3个小时的调查并尝试创建丢失的文件,我不得不重新考虑该方法。
我删除了本地@angular模块并在全球重新安装:
npm install --save-dev @angular/cli@latest
npm install --save-dev @angular/compiler-cli@latest
npm install --save-dev @angular/compiler@latest
npm install --save-dev @angular/core@latest
Run Code Online (Sandbox Code Playgroud)
我发现我的项目具有自定义架构,因此我必须运行npm start