uni-app 3.2.9版本app无限编译反复运行

uni-app 3.2.9版本app无限编译反复运行

示例代码:

项目会无限编译

操作步骤:

项目会无限编译

预期结果:

项目会无限编译

实际结果:

项目会无限编译

bug描述:

10:47:59.309 WARNING: Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:47:59.314 (Emitted value instead of an instance of Error) <n-cell v-for="user in items">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.  
10:47:59.318 Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:47:59.323 (Emitted value instead of an instance of Error) <yylp-cell v-for="radio in pitem.now_field.options">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.  
10:47:59.329  DONE  Build complete. Watching for changes...  
10:47:59.333 项目 'les_chat' 编译成功。  
10:47:59.339 正在热重载...  
10:47:59.528 生成路由映射表-ok  
10:48:00.705 WARNING: Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:48:00.706 (Emitted value instead of an instance of Error) <n-cell v-for="user in items">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.  
10:48:00.712 Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:48:00.718 (Emitted value instead of an instance of Error) <yylp-cell v-for="radio in pitem.now_field.options">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.  
10:48:00.726  DONE  Build complete. Watching for changes...  
10:48:00.731 项目 'les_chat' 编译成功。  
10:48:00.732 正在热重载...  
10:48:00.739 生成路由映射表-ok  
10:48:01.389 WARNING: Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:48:01.390 (Emitted value instead of an instance of Error) <n-cell v-for="user in items">: component lists rendered with v-for should have explicit keys. See https://vuejs.org/guide/list.html#key for more info.  
10:48:01.397 Module Warning (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  
10:48:01.416 已停止运行...
产品分类 PC开发环境操作系统 PC开发环境操作系统版本号 HBuilderX版本号
HbuilderX Windows win10 3.2.9

更多关于uni-app 3.2.9版本app无限编译反复运行的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

//development开发,production:正式
if (process.env.NODE_ENV == ‘development’) {
const fs = require(‘fs’);
let routesMap_nameMap = {};
let routesMap_pathMap = {};
modules.forEach((item, index) => {
routesMap_nameMap[item.name] = item;
routesMap_pathMap[item.path] = item;
});
//生成映射关系表
fs.writeFileSync(process.env.UNI_INPUT_DIR + ‘/.dnvue/common/pageMap.js’,
‘module.exports = {nameMap:’ +
JSON.stringify(routesMap_nameMap) + ‘,pathMap:’ +
JSON.stringify(routesMap_pathMap) + ‘};’);
console.log(“生成路由映射表-ok”);
} 这个版本这段代码会无线热重载

更多关于uni-app 3.2.9版本app无限编译反复运行的实战教程也可以访问 https://www.itying.com/category-93-b0.html


根据你提供的日志信息,这个问题并非真正的“无限编译”,而是由热重载(HMR)触发的一系列连续编译循环。核心原因在于你的代码中存在 Vue 警告,这些警告被热重载机制处理后,意外地再次触发了文件变更检测,从而导致循环。

问题根源分析:

  1. 代码警告触发循环:你的模板中存在两处 v-for 循环未提供 :key 绑定(<n-cell><yylp-cell>)。在开发模式下,Vue 编译器会对此发出警告。
  2. 热重载机制:HBuilderX 的热重载功能在检测到文件变化后,会重新编译并尝试更新应用。在某些情况下,处理警告或生成 source map 等操作可能会被文件监视系统误判为项目文件发生了新的变更。
  3. 循环形成:编译 → 警告输出 → 热重载 → 文件系统被检测到变更(可能是由警告处理或日志写入间接引起)→ 再次触发编译,如此反复。

解决方案:

立即解决循环问题:

  • 临时禁用热重载:在 manifest.json 的源码视图中,添加或修改以下配置:
    "h5" : {
        "devServer" : {
            "hot" : false
        }
    }
    
    这将禁用 H5 平台的热重载。对于 App 平台,目前没有直接的配置项,但可以尝试在 HBuilderX 中运行到浏览器或关闭自动运行。
  • 重启 HBuilderX:有时简单的重启可以打断这个循环状态。

根本性修复代码: 为所有 v-for 循环的节点添加唯一的 :key 绑定。这是 Vue 的强制要求,不仅能解决警告,也是列表渲染的最佳实践,可以避免潜在的渲染错误和性能问题。

<!-- 示例:为 n-cell 添加 key -->
<n-cell v-for="user in items" :key="user.id">
  <!-- 内容 -->
</n-cell>

<!-- 示例:为 yylp-cell 添加 key -->
<yylp-cell v-for="radio in pitem.now_field.options" :key="radio.value">
  <!-- 内容 -->
</yylp-cell>
回到顶部