dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
40.18k stars 3.64k forks source link

HBuilderX升级到2.6.8,TypeScript项目在导入组件时仍然报错 Unknown custom element: #1505

Closed gxsww closed 4 years ago

gxsww commented 4 years ago

问题描述 之前看到有人反馈过这个问题,回复说2.6.6已修复,但我升级到2.6.8这个问题仍然存在。 用vue-cli方式创建的TypeScript项目在导入组件时报错 Unknown custom element:

复现步骤 1.创建项目 vue create -p dcloudio/uni-preset-vue my-project 2.选择默认模板(TypeScript) 3.从插件市场List 列表插件,按照说明导入

<template>
    <view class="content">
        <view>
            <text class="title">{{title}}</text>
        </view>
        <uni-list>
            <uni-list-item title="第一行" note=""></uni-list-item>
            <uni-list-item title="第二行" note=""></uni-list-item>
        </uni-list>
        <!-- 这样写不会输出错误 -->
        <!-- <uniList>
            <uniListItem title="第一行" note=""></uniListItem>
            <uniListItem title="第二行" note=""></uniListItem>
        </uniList> -->
    </view>
</template>

<script lang="ts">
    import uniList from "@/components/uni-list/uni-list.vue"
    import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
    import {
        Component,
        Vue,
        Inject
    } from 'vue-property-decorator';
    @Component({
        components: {
            uniList,
            uniListItem}
    })
    export default class Index extends Vue {
        title:string= 'Hello'
        onLoad() {

        }

    }
</script>

<style>
    .content {
        text-align: center;
        height: 400upx;
    }
    .logo{
        height: 200upx;
        width: 200upx;
        margin-top: 200upx;
    }
    .title {
        font-size: 36upx;
        color: #8f8f94;
    }
</style>

预期结果 不报错

实际结果 报错 vue.runtime.esm.js:619 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in

系统信息:

gxsww commented 4 years ago

package.json


{
  "name": "uni-app-ts-268",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "npm run dev:h5",
    "build": "npm run build:h5",
    "build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
    "build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
    "build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
    "build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
    "build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
    "build:mp-qq": "cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build",
    "build:mp-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
    "build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
    "dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
    "dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",
    "dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
    "dev:mp-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
    "dev:mp-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
    "dev:mp-qq": "cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch",
    "dev:mp-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
    "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
    "info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js"
  },
  "dependencies": {
    "@dcloudio/uni-app-plus": "^2.0.0-26520200314001",
    "@dcloudio/uni-h5": "^2.0.0-26520200314001",
    "@dcloudio/uni-helper-json": "*",
    "@dcloudio/uni-mp-alipay": "^2.0.0-26520200314001",
    "@dcloudio/uni-mp-baidu": "^2.0.0-26520200314001",
    "@dcloudio/uni-mp-qq": "^2.0.0-26520200314001",
    "@dcloudio/uni-mp-toutiao": "^2.0.0-26520200314001",
    "@dcloudio/uni-mp-weixin": "^2.0.0-26520200314001",
    "@dcloudio/uni-stat": "^2.0.0-26520200314001",
    "flyio": "^0.6.2",
    "node-sass": "^4.13.1",
    "regenerator-runtime": "^0.12.1",
    "sass-loader": "^8.0.2",
    "vue": "^2.6.11",
    "vue-class-component": "^6.3.2",
    "vue-property-decorator": "^8.0.0",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@babel/plugin-syntax-typescript": "^7.2.0",
    "@dcloudio/types": "*",
    "@dcloudio/uni-cli-shared": "^2.0.0-26520200314001",
    "@dcloudio/uni-migration": "^2.0.0-26520200314001",
    "@dcloudio/uni-template-compiler": "^2.0.0-26520200314001",
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-26520200314001",
    "@dcloudio/vue-cli-plugin-uni": "^2.0.0-26520200314001",
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.0-26520200314001",
    "@dcloudio/webpack-uni-mp-loader": "^2.0.0-26520200314001",
    "@dcloudio/webpack-uni-pages-loader": "^2.0.0-26520200314001",
    "@vue/cli-plugin-babel": "3.5.1",
    "@vue/cli-plugin-typescript": "^3.5.1",
    "@vue/cli-service": "~4.2.0",
    "babel-plugin-import": "^1.11.0",
    "postcss-comment": "^2.0.0",
    "typescript": "^3.0.0",
    "vue-template-compiler": "^2.6.11"
  },
  "browserslist": [
    "Android >= 4",
    "ios >= 8"
  ],
  "uni-app": {
    "scripts": {}
  }
}
fxy060608 commented 4 years ago

cli工程跟HBuilderX版本没关系,你要升级的是cli的版本,npm update

gxsww commented 4 years ago

好的,知道了,谢谢 我是升级后又新建了一个项目,我以为这样cli就是最新的了。 现在已经可以了。