Angular 自定义schematics运行旧版本 缓存清除无效问题求助
解决方案
你之前排查清除的都是npm相关的缓存,而自定义schematics运行本地版本时的旧代码来源和npm无关,按以下步骤操作即可解决:
1. 确认TypeScript已编译为最新的JS文件
你package.json中配置的入口是dist/index.js,所有对index.ts的修改都需要编译后才会生效:
- 单次编译执行:
npm run build - 开发时建议开终端常驻自动编译:
npm run build:watch - 排查验证:直接打开
dist/index.js搜索你已删除的console.log,如果能搜到说明编译未生效,先删除整个dist目录再重新编译即可。
2. 清除schematics-cli专属缓存
@angular-devkit/schematics-cli有独立于npm的全局缓存目录,你之前删的npm缓存对它无效:
- macOS/Linux执行:
rm -rf ~/.angular-devkit/schematics/ - Windows执行:删除
C:\Users\<你的用户名>\.angular-devkit\schematics\目录
3. 运行时强制禁用缓存
执行schematics命令时添加--no-schematics-cache参数即可跳过缓存加载:
schematics .:ng-new-gci --no-schematics-cache
额外排查项
如果你之前用过npm link将该包链接到全局测试,执行以下命令解除链接:
npm unlink gci-angular-base -g
内容的提问来源于stack exchange,提问作者Chris Wilson
相关产品推荐
相关产品推荐

