uni-app vue3 小程序import引入首次运行到小程序无法找到import函数
uni-app vue3 小程序import引入首次运行到小程序无法找到import函数
操作步骤:
- 打开测试项目运行到小程序开发工具,/pages/index/index -> onload 内函数无法正常运行
- 在hbuilderx编辑任意位置保存后,/pages/index/index -> onload 内函数可以正常运行
预期结果:
- onload 内函数可以正常运行
实际结果:
- onload 内函数首次无法正常运行
bug描述:
- vue3 小程序import引入首次运行到小程序无法找到import函数
| 项目属性 | 值 |
|------------------|------------------------|
| 产品分类 | uniapp/小程序/微信 |
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | macos big sur 11.6(20g165) |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 3.3.4 |
| 第三方开发者工具版本号 | 1.05.2111300 |
| 基础库版本号 | 2.21.1 |
| 项目创建方式 | HBuilderX |
更多关于uni-app vue3 小程序import引入首次运行到小程序无法找到import函数的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
static 目录用于存放静态资源,存放在此目录的 js 文件不会被编译,详见文档说明Tips
更多关于uni-app vue3 小程序import引入首次运行到小程序无法找到import函数的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个典型的 uni-app 编译缓存问题。首次运行时,import 函数可能未被正确编译到小程序环境中。
解决方案:
-
清理编译缓存:
- 删除
unpackage目录 - 删除
node_modules目录 - 重新运行
npm install或yarn install - 重新编译运行到小程序
- 删除
-
检查 import 语法:
- 确保使用的是 Vue 3 的动态导入语法:
const module = await import('@/utils/your-module.js') - 避免在顶层作用域使用动态 import,应在生命周期函数内调用
- 确保使用的是 Vue 3 的动态导入语法:
-
配置优化:
- 在
vue.config.js中配置:module.exports = { transpileDependencies: true }
- 在

