当我尝试运行“ng serve”时,我遇到了以下问题:
> ./src/main.ts中的错误
模块构建失败:错误:检测到Angular Compiler但它是错误类的实例。
这可能意味着您安装了几个@ ngtools / webpack包。您可以使用npm ls @ngtools/webpack
进行检查,然后删除多余的副本。
遵循这个建议:
$ npm ls @ ngtools / webpack test@0.0.0 C:\ Daten \ Projects \ test
-- @angular/cli@1.7.2
- @ ngtools / webpack @ 1.10.1
因此没有安装多个webpack版本。我尝试在使用@angular/cli
和npm cache clean -f
后全局,本地重新安装npm cache verify
....我对webpack
做了同样的事情。可悲的是,没有其他人真正遇到这个问题,这让人难以解决。我的谷歌研究没有成功,因为我发现的所有内容都是将中文翻译成中文和这两个SO链接(这不能为我提供解决方案):
https://stackoverflow.com/search?q=Angular+Compiler+was+detected
Error: several @ngtools/webpack packages installed
Share `node_modules` between Meteor 1.6 server & Angular CLI client Angular-Meteor subprojects?
我的package.json:
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^1.7.2",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"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": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "2.6.2"
}
}
注意:
项目可以在另一台PC上编译 - 唯一的区别是操作系统(他在使用win10时使用win7)。
问候,周末愉快,
Messerbill
答案 0 :(得分:0)
我遇到了同样的问题。不确定它是否与升级到Angular CLI 1.7.2有关(我从1.6.1升级)。
这就是我解决它的方法:
node_modules
文件夹(刚刚运行npm install
没有修复它)。npm install
。ng build
。ng serve
。我从评论中看到你已经尝试了一些,但这些步骤对我有用: - )
"devDependencies": {
"@angular/cli": "1.7.2",
"@angular/compiler-cli": "5.2.7",
"@types/node": "9.4.6",
"codelyzer": "4.2.1",
"ts-node": "5.0.1",
"tslint": "5.9.1",
"typescript": "2.4.2"
}
答案 1 :(得分:0)
最后。更新我的全局打字稿版本修复了它。现在全局使用tsc 2.6.2并且它可以工作。
现在使用以下内容:
2.6.2
(全局和本地)1.7.2
(全局和本地)
3.11.0
8.9.1
5.5.1
答案 2 :(得分:0)
尝试删除您的node_modules,并使用yarn install
代替npm install
。它对我有用:)
答案 3 :(得分:0)
要删除多余的副本并从package.json
中的依赖项中删除,您将需要使用save标志:
npm uninstall --save webpack
如果您已将软件包安装为“ devDependency”(即使用--save-dev
),则--save
不会将其从package.json中删除。您需要使用--save-dev
来卸载它。
这是上面命令正常运行的结果。
$ npm ls @ngtools/webpack
angularapp@0.0.0 C:\Apache24\htdocs\angularapp
+-- @angular-devkit/build-angular@0.7.5
| `-- @ngtools/webpack@6.1.5
`-- @ngtools/webpack@6.2.1
$ npm uninstall --save webpack
> node-sass@4.9.3 install C:\Apache24\htdocs\angularapp\node_modules\node-sass
> node scripts/install.js
Cached binary found at C:\Users\user\AppData\Roaming\npm-cache\node-sass\4.9.3\win32-x64-59_binding.node
> node-sass@4.9.3 postinstall C:\Apache24\htdocs\angularapp\node_modules\node-sass
> node scripts/build.js
Binary found at C:\Apache24\htdocs\angularapp\node_modules\node-sass\vendor\win32-x64-59\binding.node
Testing binary
Binary is fine
added 1106 packages in 677.641s
$ npm ls @ngtools/webpack
angularapp@0.0.0 C:\Apache24\htdocs\angularapp
`-- @angular-devkit/build-angular@0.7.5
`-- @ngtools/webpack@6.1.5