uni-app 使用node_modules模块时,项目无法在微信开发者工具中运行
uni-app 使用node_modules模块时,项目无法在微信开发者工具中运行
项目信息 | 详细信息 |
---|---|
产品分类 | uniapp/小程序/微信 |
PC开发环境操作系统 | Windows |
PC开发环境操作系统版本号 | win10专业版 |
HBuilderX类型 | 正式 |
HBuilderX版本号 | 3.1.6 |
第三方开发者工具版本号 | 1.02.2103190 |
基础库版本号 | 2.16.0 |
项目创建方式 | HBuilderX |
操作步骤:
"easycom": {
"autoscan": true,
"custom": {
"sf-(.*)": "sf-ui/components/sf-$1/sf-$1.vue"
}
},
pages: [
{
"path": "node_modules/sf-ui/pages/sf-avatar-cropper/sf-avatar-cropper",
"style": {
"navigationBarTitleText": "avatar-cropper"
}
]
预期结果:
项目在微信开发者工具能正常运行
实际结果:
未知
bug描述:
同时在 easycom
及 pages
内使用node_modules里模块,项目无法在微信开发者工具运行
生成了两个node_modules目录
微信开发者工具控制台错误信息
更多关于uni-app 使用node_modules模块时,项目无法在微信开发者工具中运行的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app 使用node_modules模块时,项目无法在微信开发者工具中运行的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在uni-app项目中同时使用easycom
和pages
配置引用node_modules模块时,微信开发者工具无法运行的主要原因是路径解析冲突和重复依赖。
从错误信息看,问题出现在:
- 路径解析失败:微信开发者工具无法正确解析node_modules中的页面路径
- 重复的node_modules目录:可能导致模块加载冲突
解决方案:
- 移除pages中的node_modules路径引用
// 不建议直接在pages中引用node_modules路径
pages: [
{
"path": "pages/your-local-page", // 使用本地页面路径
"style": {
"navigationBarTitleText": "页面标题"
}
}
]
- 保持easycom配置,通过组件方式使用
// 在页面中通过组件形式使用,而不是作为页面引用
<template>
<sf-avatar-cropper />
</template>