这是我的 Angular5 项目结构。
tsconfig.app.json
和package.json
都包含此部分
"include": [
"/src/main.ts",
"/src/polyfills.ts"
]
但无论我尝试什么,我仍然收到此错误:
\polyfills.ts & \main.ts is missing from the TypeScript compilation.
Please make sure it is in your tsconfig via the 'files' or 'include' property.
tsconfig.json
{
"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": []
},
"include": [
"main.ts",
"polyfills.ts"
],
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
找到解决方案。问题是因为我位于符号链接目录中( $HOME/dev -> d:\dev\ ) 移动到原始目录 (d:\dev) 并运行命令,它就可以工作了。
编辑 angular.json 以在节点
projects/project/architect/build/options
下添加以下属性应该有助于使 "preserveSymlinks": true
工作。
{
...
"projects": {
"<your_project_name>": {
...
"architect": {
"build": {
...
"options": {
...
"preserveSymlinks": true
}
...
}
}
}
}
}
今天在尝试在 Windows 10 上使用 Git Bash 构建 Angular 9 应用程序时遇到了这个问题。
结果是文件路径太长/嵌套,Git Bash 无法处理!或者 Git Bash 在某些地方使用符号链接。
从 Cmd / PowerShell 运行
ng build
,效果很好。
我也遇到过这个问题一段时间,我只是通过更改项目的位置来解决它。我把它放在系统以外的磁盘中(例如:d:、e:...)
我仅遇到了我的
src/polyfills.ts
文件的问题,因为 "files"
中的 tsconfig.app.json
数组中缺少该文件。
这可能是因为您使用的是绝对路径。
尝试更改:
"/src/main.ts",
到
"src/main.ts",
(或者可能只是
"main.ts"
)