javascript - 从项目中删除文件时包裹 bundler "ENOENT: no such file or directory"

标签 javascript parceljs

从使用 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-cachedist 文件夹并再次运行命令。 (注意:在 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/

相关文章:

javascript - 同类最佳的 JavaScript 数据表小部件/库

javascript - 更改单选按钮和复选框的默认行为

javascript - 如何将 Assets 文件包含在 parcel js 中?

javascript - Electron.js/包裹错误: fs.存在Sync不是函数

javascript - 在远程主机上导入所有模块时的包裹构建问题

node.js - 有没有办法打包使用 express 和 ejs 的 nodejs 应用程序?

parceljs - 有没有办法像在 Webpack 中一样在 Parcel 中代理请求?

javascript - Three.js - Torus 不绕 0z 轴旋转

javascript - 如何在angularjs http中添加访问 token

javascript - 为什么我的 angular.js 应用程序不能在 ie7 上运行?