冉娃娃
冉娃娃
  • 发布:2019-11-15 16:26
  • 更新:2020-07-02 13:25
  • 阅读:1416

【报Bug】条件编译引报错

分类:uni-app

业务背景

开发多端小程序,部分业务组件只在支付宝小程序下面使用.所以在import,component以及HTML里分别加了条件编译.

  • 在支付宝和网页下一切ok.

but

今天开始编译到微信和头条小程序时就报错

示例代码

示例代码是最新版,刚刚初始化的默认模板代码,只是添加了一个测试用的vue组件.

<template>  
  <view class="content">  
    <image  
      class="logo"  
      src="/static/logo.png"  
    ></image>  
    <view>  
      <text class="title">{{title}}</text>  
      <!-- #ifdef MP-ALIPAY -->  
      <test />  
      <!-- #endif -->  
    </view>  
  </view>  
</template>  

<script>  
// #ifdef MP-ALIPAY  
import test from './test';  
// #endif  
export default {  
  components: {  
    // #ifdef MP-ALIPAY  
    test,  
    // #endif  
  },  
  ...

test.vue内容

<template>  
  <view class="content">  
    {{ text }}  
  </view>  
</template>  

<script>  
export default {  
  data() {  
    return {  
      text: 'component',  
    };  
  },  
  onLoad() {  
  },  
  methods: {},  
};  
</script>

错误内容

ZMN-001@DESKTOP-NAC2B94 MINGW64 /e/test/my-project (master)  
$ yarn run dev:mp-weixin  
yarn run v1.17.3  
$ cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch  
当前项目编译模式:自定义组件模式。编译模式差异见:https://ask.dcloud.net.cn/article/35843  
请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。若要正式发布,请点击发行菜单或使用cli发布命令进行发布  
正在编译中...  

-  开始编译当前项目至 mp-weixin 平台...  
 ERROR  Failed to compile with 1 errors16:18:46  

 error  in ./src/pages/index/index.vue?vue&type=script&lang=js&  

Module build failed (from ./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js):  
Error: 组件 test 引用错误,仅支持 import 方式引入组件  
    at E:\test\my-project\node_modules\@dcloudio\webpack-uni-mp-loader\lib\babel\util.js:37:13  
    at Array.forEach (<anonymous>)  
    at parseComponents (E:\test\my-project\node_modules\@dcloudio\webpack-uni-mp-loader\lib\babel\util.js:31:9)  
    at handleObjectExpression (E:\test\my-project\node_modules\@dcloudio\webpack-uni-mp-loader\lib\babel\scoped-component-traverse.js:19:24)  
    at ExportDefaultDeclaration (E:\test\my-project\node_modules\@dcloudio\webpack-uni-mp-loader\lib\babel\scoped-component-traverse.js:36:9)  
    at NodePath._call (E:\test\my-project\node_modules\@babel\traverse\lib\path\context.js:55:20)  
    at NodePath.call (E:\test\my-project\node_modules\@babel\traverse\lib\path\context.js:42:17)  
    at NodePath.visit (E:\test\my-project\node_modules\@babel\traverse\lib\path\context.js:90:31)  
    at TraversalContext.visitQueue (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:112:16)  
    at TraversalContext.visitMultiple (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:79:17)  
    at TraversalContext.visit (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:138:19)  
    at Function.traverse.node (E:\test\my-project\node_modules\@babel\traverse\lib\index.js:84:17)  
    at NodePath.visit (E:\test\my-project\node_modules\@babel\traverse\lib\path\context.js:97:18)  
    at TraversalContext.visitQueue (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:112:16)  
    at TraversalContext.visitSingle (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:84:19)  
    at TraversalContext.visit (E:\test\my-project\node_modules\@babel\traverse\lib\context.js:140:19)  

 @ ./src/pages/index/index.vue?vue&type=script&lang=js& 1:0-554 1:570-573 1:575-1126 1:575-1126  
 @ ./src/pages/index/index.vue  
 @ ./src/main.js?{"page":"pages%2Findex%2Findex"}  

 ERROR  Build failed with errors.  
error Command failed with exit code 1.  
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.  
2019-11-15 16:26 负责人:无 分享
已邀请:
aimernos

aimernos

跟我一样,还没解决

该问题目前已经被锁定, 无法添加新回复