[英]Can't create an Angular 5 project using angular-cli
我正在尝试创建一个新的Angular 5项目。 我已经安装了@ angular / cli版本1.6.3并输入:
ng new project --routing
安装完所有内容后,我做了:
cd project
ng build
并得到以下错误:
模块构建失败:错误:TypeScript编译中缺少d:... \\ project \\ src \\ main.ts。 请通过“文件”或“包含”属性确保它在您的tsconfig中。
模块构建失败:错误:TypeScript编译中缺少d:... \\ project \\ src \\ polyfills.ts。 请通过“文件”或“包含”属性确保它在您的tsconfig中。
在Angular github页面上有关于此的一些讨论,但是除了说这已经解决,或者指出node_modules
中的ts
文件所在的问题外,这没有帮助。
我们在这里使用Windows 10。
编辑:tsconfig文件是(有两个):
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
另一个(src / tsconfig.app.json):
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
这些都是由ng new
创建的。
哦,亲爱的,我忘了回答这个问题! 很久以前在Angular github中得到了回答。
在Angular 5中,您需要为ng build
和ng serve
添加--preserve-symlinks
。
在Angular 6中,您无法再执行此操作,而需要添加
"preserveSymlinks": true,
到angular.json
,将其放在项目的architect/build/options
下。
通过在终端/控制台窗口中运行节点-v和npm -v来验证您至少正在运行节点6.9.x和npm3.xx。 较旧的版本会产生错误,但是较新的版本可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.