从使用 Parcel 捆绑程序的项目中删除几个文件后,命令 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-cache
和 dist
文件夹并再次运行命令。 (注意:在 Parcel 1.x 版本中,缓存文件夹仅称为 .cache
。)
提案
为此添加清理脚本并在每次构建包裹之前运行它:
"scripts": {
"cleanup": "rm -rf .parcel-cache dist",
"dev": "npm run cleanup && parcel ./index.html",
...
}
您还可以使用 rimraf lib 执行跨平台清理任务。 https://www.npmjs.com/package/rimraf 。所以脚本将如下所示:
"scripts": {
"cleanup": "rimraf .parcel-cache dist",
"dev": "npm run cleanup && parcel ./index.html",
...
}
关于javascript - 从项目中删除文件时包裹 bundler "ENOENT: no such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59196917/