9***@qq.com
9***@qq.com
  • 发布:2025-09-16 10:09
  • 更新:2025-09-16 11:09
  • 阅读:26

【报Bug】命令行创建uni+vue3项目开发微信小程序插件,编译后运行报无法找到插件

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

第三方开发者工具版本号: 1.06.2504030

基础库版本号: 2.30.4

项目创建方式: CLI

CLI版本号: 3.0.0-4070620250821001

操作步骤:

1.根据官方提供的文档,使用命令行创建vue3+uniapp小程序项目,开发小程序插件。
package.json新增以下代码:

  "scripts": {  
...  
    "dev:mp-wx-plugin-official": "yarn dev:custom mp-wx-plugin --plugin test-plugin", // 由官方文档提供  
    "dev:mp-wx-plugin": "cross-env NODE_ENV=development UNI_OUTPUT_DIR=./dist/dev/plugin-app/plugin uni -p mp-wx-plugin --plugin plugin", // 指定目录生成plugin项目文件  
    "dev:mp-wx": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin UNI_OUTPUT_DIR=./dist/dev/plugin-app/miniprogram uni -p mp-weixin"  // 指定目录生成小程序项目文件  
},  
  "uni-app": {  
    "scripts": {  
...  
      "mp-wx-plugin": {  
        "title": "微信小程序插件",  
        "env": {  
          "UNI_PLATFORM": "mp-weixin"  
        },  
        "define": {  
          "MP-WX-PLUGIN": true  
        }  
      }  
    }  
  },

2.分别运行npm run dev:mp-wx-plugin和npm run dev:mp-wx进行编译,编译后在dist/dev/plugin-app根目录中新增project.config.json和project.private.config.json

// project.config.json  
{  
    "miniprogramRoot": "miniprogram/",  
    "pluginRoot": "plugin/",  
    "compileType": "plugin",  
    "libVersion": "latest",  
    "srcMiniprogramRoot": "miniprogram/",  
    "appid": "wx62de7623ad634e12",  
    "setting": {  
        "es6": false,  
        "postcss": false,  
        "compileWorklet": false,  
        "minified": false,  
        "uglifyFileName": false,  
        "uploadWithSourceMap": true,  
        "enhance": false,  
        "packNpmManually": false,  
        "packNpmRelationList": [],  
        "minifyWXSS": true,  
        "minifyWXML": true,  
        "localPlugins": false,  
        "condition": false,  
        "swc": false,  
        "disableSWC": true,  
        "babelSetting": {  
            "ignore": [],  
            "disablePlugins": [],  
            "outputPath": ""  
        },  
        "disableUseStrict": false,  
        "useCompilerPlugins": false,  
        "ignoreUploadUnusedFiles": true  
    },  
    "simulatorPluginLibVersion": {},  
    "packOptions": {  
        "ignore": [],  
        "include": []  
    },  
    "editorSetting": {}  
}
// project.private.config.json  
{  
    "libVersion": "2.30.4",  
    "projectname": "miniprogram-1",  
    "setting": {  
        "urlCheck": true,  
        "coverView": false,  
        "lazyloadPlaceholderEnable": false,  
        "skylineRenderEnable": false,  
        "preloadBackgroundData": false,  
        "autoAudits": false,  
        "useApiHook": true,  
        "useApiHostProcess": true,  
        "showShadowRootInWxmlPanel": false,  
        "useStaticServer": false,  
        "useLanDebug": false,  
        "showES6CompileOption": false,  
        "compileHotReLoad": false,  
        "bigPackageSizeSupport": false,  
        "checkInvalidKey": true,  
        "ignoreDevUnusedFiles": true  
    }  
}

3.打开微信开发者工具-导入项目(开发模式选择:插件)

预期结果:

开发者工具正常运行编译后的项目,无报错

实际结果:

开发者工具报错TypeError: wx$2.canIUse is not a function,且提示找不到插件

TypeError: wx$2.canIUse is not a function  
    at vendor.js:1665  
    at VM6866 WASubContext.js:1  
    at f.runWith (VM6866 WASubContext.js:1)  
    at I (VM6866 WASubContext.js:1)  
    at VM6866 WASubContext.js:1  
    at app.js:3  
    at VM6866 WASubContext.js:1  
    at f.runWith (VM6866 WASubContext.js:1)  
    at I (VM6866 WASubContext.js:1)  
    at VM6866 WASubContext.js:1(env: Windows,mp,1.06.2504030; lib: 2.30.4)  

Component is not found in path "plugin://wx62de7623ad634e12/chanin-transfer" (using by "wxPages/index/index")(env: Windows,mp,1.06.2504030; lib: 2.30.4)

bug描述:

命令行创建uni+vue3项目开发微信小程序插件,编译后运行报无法找到插件,且微信开发者工具报错提示

TypeError: wx$2.canIUse is not a function  
    at vendor.js:1665  
    at VM6866 WASubContext.js:1  
    at f.runWith (VM6866 WASubContext.js:1)  
    at I (VM6866 WASubContext.js:1)  
    at VM6866 WASubContext.js:1  
    at app.js:3  
    at VM6866 WASubContext.js:1  
    at f.runWith (VM6866 WASubContext.js:1)  
    at I (VM6866 WASubContext.js:1)  
    at VM6866 WASubContext.js:1(env: Windows,mp,1.06.2504030; lib: 2.30.4)

附件plugin-app为编译后的项目文件

2025-09-16 10:09 负责人:无 分享
已邀请:
DCloud_UNI_JBB

DCloud_UNI_JBB

看起来编译产物没什么问题,测试一下原生微信小程序这样写是否有问题

  • 9***@qq.com (作者)

    把plugin文件单独拎出来,放到微信开发者工具自己生成的插件项目中,根本运行不了,报错提示TypeError: wx$2.canIUse is not a function,页面显示空白

    2025-09-16 11:33

要回复问题请先登录注册