从项目中删除文件时的包裹捆绑器 "ENOENT: no such file or directory"

Parcel bundler "ENOENT: no such file or directory" when delete files from project

在我从使用 Parcel bundler 的项目中删除几个文件后,命令 parcel ./index.html 开始输出以下错误:

Cannot read property 'type' of undefined
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:654:54)
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:721:12)
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:721:12)
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:721:12)
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:721:12)
at Bundler.createBundleTree (<project_root>/node_modules/parcel-bundler/src/Bundler.js:721:12)
at Bundler.bundle (<project_root>/node_modules/parcel-bundler/src/Bundler.js:298:14)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)

解决方案

删除 .parcel-cachedist 文件夹并再次执行 运行 命令。 (注意:缓存文件夹在 1.x 版本的 Parcel 中仅被调用 .cache。)

提案

每次在包裹构建之前为此添加清理脚本和运行它:

 "scripts": {
   "cleanup": "rm -rf .parcel-cache dist",
   "dev": "npm run cleanup && parcel ./index.html",
   ...
 }