uni-app CLI项目微信小程序发行和调试时uni_modules组件打包后未看见components目录

发布于 1周前 作者 itying888 来自 Uni-App

uni-app CLI项目微信小程序发行和调试时uni_modules组件打包后未看见components目录

| 开发环境         | 版本号     | 项目创建方式 |
|------------------|------------|--------------|
| Windows          | win 11     | CLI          |
| HBuilderX        | 3.97       |              |
| 第三方开发者工具 | 1.06.2310080 |            |
| 基础库           | 3.1.5      |              |
| CLI              | 4.0.3      |              |

### bug描述:
【报BugCLI项目微信小程序发行和调试uni_modules组件打包后没有看见components目录

### 示例代码:
```p
重复打包还是失效,没有打包到uview-plus控件

操作步骤:

重复打包还是失效,没有打包到uview-plus控件

预期结果:

重复打包还是失效,没有打包到uview-plus控件

实际结果:

重复打包还是失效,没有打包到uview-plus控件

2 回复

解决了吗?我这里也遇到了


在 Uni-App CLI 项目中,如果你在微信小程序发行和调试时发现 uni_modules 组件打包后没有生成 components 目录,可能是以下原因导致的:


1. uni_modules 组件未正确引入

  • 确保你在页面或组件中正确引入了 uni_modules 中的组件。
  • 例如:
    <template>
      <view>
        <my-component></my-component>
      </view>
    </template>
    <script>
    import MyComponent from '@/uni_modules/my-component/components/my-component/my-component.vue';
    export default {
      components: {
        MyComponent
      }
    }
    </script>

2. uni_modules 组件未正确注册

  • 确保 uni_modules 组件在 pages.jsonmain.js 中正确注册。
  • 例如,在 pages.json 中:
    {
      "pages": [
        {
          "path": "pages/index/index",
          "style": {
            "usingComponents": {
              "my-component": "/uni_modules/my-component/components/my-component/my-component"
            }
          }
        }
      ]
    }

3. uni_modules 组件未正确打包

  • Uni-App CLI 在打包时,默认会将 uni_modules 中的组件打包到 dist/dev/mp-weixin/components 目录下。
  • 如果未生成 components 目录,可能是以下原因:
    • 未正确配置 uni_modules:确保 uni_modules 目录结构符合规范。
    • 未正确运行打包命令:确保运行的是 npm run dev:mp-weixinnpm run build:mp-weixin
    • 缓存问题:尝试清理缓存后重新打包:
      npm run clean
      npm run dev:mp-weixin

4. 检查 uni_modules 目录结构

  • 确保 uni_modules 目录结构正确,例如:
    uni_modules/
      my-component/
        components/
          my-component/
            my-component.vue
            my-component.json
            my-component.wxss
            my-component.wxml

5. 检查微信开发者工具

  • 在微信开发者工具中,确保项目路径正确指向 dist/dev/mp-weixin
  • 如果仍然看不到 components 目录,可以尝试以下操作:
    • 重新编译项目。
    • 清除微信开发者工具的缓存并重启。

6. 检查 Uni-App 版本

  • 确保你使用的是最新版本的 Uni-App CLI,旧版本可能存在兼容性问题。
  • 更新 Uni-App CLI:
    npm install @dcloudio/uni-cli -g
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!