基础Angular ng项目运行scullyio时触发TS5042编译错误
Angular 11标准项目运行Scully报TS5042错误
复现步骤
- 安装匹配版本@angular/cli
- 执行
ng new scully创建全新基础Angular项目 - 执行
ng build --prod完成生产构建 - 执行
npm run scully启动Scully静态生成流程
报错详情
执行Scully启动命令时,程序中断并返回以下编译错误:
> scully@0.0.0 scully > npx scully -- logging with severity "warning" using plugins from folder "./scully" Typescript error while compiling plugins. the error is: error TS5042: Option 'project' cannot be mixed with source files on a command line. undefined
环境信息
- 问题复现排查过程:曾尝试在集成@PWA能力的Angular项目中运行Scully,报错未解决;后重新创建无额外配置的空白Angular项目,相同步骤仍可复现该问题
- 核心运行环境版本:
NPM: 7.10.0 Angular CLI: 11.2.9 Node: 15.14.0 OS: win32 x64 Angular: 11.2.10 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, router Ivy Workspace: Yes Package Version --------------------------------------------------------- @angular-devkit/architect 0.1102.9 @angular-devkit/build-angular 0.1102.9 @angular-devkit/core 11.2.9 @angular-devkit/schematics 11.2.9 @angular/cli 11.2.9 @schematics/angular 11.2.9 @schematics/update 0.1102.9 rxjs 6.6.7 typescript 4.1.5
问题原因与解决方式
该错误是Scully 11.x早期版本的已知兼容问题:Scully对项目./scully目录下的插件文件做编译时,会同时在编译命令中拼接--project参数指向项目tsconfig配置文件,又手动将插件目录下的.ts文件作为源文件传入命令行,触发TypeScript的规则校验:--project参数不允许与单独传入的源文件路径共存,因此抛出TS5042错误。
可落地的解决操作:
- 检查项目根目录下的
scully文件夹:若文件夹为空、无自定义插件内容,直接删除该空文件夹后重新执行Scully命令即可 - 若
scully目录下存在自定义插件:将项目中安装的Scully版本升级到修复了该编译参数冲突问题的11.1.2及以上版本 - 临时适配方案:在项目根目录的
tsconfig.json文件中,为include字段添加scully/**/*.ts的匹配规则,将插件文件纳入项目tsconfig的编译范围,避免Scully单独传入源文件参数
内容的提问来源于stack exchange,提问作者Brett Connell
相关产品推荐
相关产品推荐

