dcloudio / uni-app

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

import {createApp} from '@/main.ts' 带来的编译问题 #4341

Closed ldc2726 closed 1 year ago

ldc2726 commented 1 year ago

问题描述 import {createApp} from '@/main.ts' app端会报错[ERROR] No loader is configured for ".vue" files: src/App.vue

复现步骤

  1. 引入了一个外部组件,其内部实现只使用了一个install方法进行了注册,即 // #ifdef VUE3 Vue.config.globalProperties.$u = $u // #endif
  2. 在main.ts中使用app.use(xxx)进行调用,但是其js方法只能通过app.config.globalProperties.$u进行调用
  3. 在使用的地方(这里是pinia)引入main.ts 中export得createApp方法,即app端出现以上错误,h5端正常

[或者可以直接贴源代码]

预期结果 导入createApp不会有对应的loader解析错误问题,或者提供其他方法来兼容vue3的此语法

实际结果 报错[ERROR] No loader is configured for ".vue" files: src/App.vue `

系统信息:

补充信息 因为编译报错是vue的loader解析问题,所以 临时解决方案,新建一个ts文件,内部exportcreateApp({}).use(xxxx),完全没有涉及vue文件,从而去使用其内部的一些js方法,但是会有一系列的警告。如下: `Feature flags VUE_OPTIONS_API, VUE_PROD_DEVTOOLS are not explicitly defined. You are running the esm-bundler build of Vue, which expects these compile-time feature flags to be globally injected via the bundler config in order to get better tree-shaking in the production bundle.

ldc2726 commented 1 year ago

Uncaught TypeError: Cannot read properties of undefined (reading 'openShare') at app-renderjs.js:84878 还有一句报错,但是不影响编译

ldc2726 commented 1 year ago

已经解决,组件提供了uni.$u的方法,这个问题不再寻求解决