p***@gmail.com
p***@gmail.com
  • 发布:2023-11-16 14:04
  • 更新:2024-11-21 14:20
  • 阅读:728

TypeError: uni is not a function

分类:uni-app

启动开发环境

npm run dev:h5

提示如下

failed to load config from app-mini/vite.config.js  
error when starting dev server:  
TypeError: uni is not a function  

package.json

{  
  "name": "app-mini",  
  "version": "0.0.2",  
  "private": true,  
  "type": "module",  
  "scripts": {  
    "dev": "npm run dev:h5",  
    "build": "npm run build:mp-weixin",  
    "upload": "node mini-cli/upload.cjs",  
    "dep-pro": "npm run build && npm run upload",  
    "dev:app": "uni -p app",  
    "dev:app-android": "uni -p app-android",  
    "dev:app-ios": "uni -p app-ios",  
    "dev:custom": "uni -p",  
    "dev:h5": "uni",  
    "dev:h5:ssr": "uni --ssr",  
    "dev:mp-alipay": "uni -p mp-alipay",  
    "dev:mp-baidu": "uni -p mp-baidu",  
    "dev:mp-jd": "uni -p mp-jd",  
    "dev:mp-kuaishou": "uni -p mp-kuaishou",  
    "dev:mp-lark": "uni -p mp-lark",  
    "dev:mp-qq": "uni -p mp-qq",  
    "dev:mp-toutiao": "uni -p mp-toutiao",  
    "dev:mp-weixin": "uni -p mp-weixin",  
    "dev:mp-xhs": "uni -p mp-xhs",  
    "dev:quickapp-webview": "uni -p quickapp-webview",  
    "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",  
    "dev:quickapp-webview-union": "uni -p quickapp-webview-union",  
    "build:app": "uni build -p app",  
    "build:app-android": "uni build -p app-android",  
    "build:app-ios": "uni build -p app-ios",  
    "build:custom": "uni build -p",  
    "build:h5": "uni build",  
    "build:h5:ssr": "uni build --ssr",  
    "build:mp-alipay": "uni build -p mp-alipay",  
    "build:mp-baidu": "uni build -p mp-baidu",  
    "build:mp-jd": "uni build -p mp-jd",  
    "build:mp-kuaishou": "uni build -p mp-kuaishou",  
    "build:mp-lark": "uni build -p mp-lark",  
    "build:mp-qq": "uni build -p mp-qq",  
    "build:mp-toutiao": "uni build -p mp-toutiao",  
    "build:mp-weixin": "uni build -p mp-weixin",  
    "build:mp-xhs": "uni build -p mp-xhs",  
    "build:quickapp-webview": "uni build -p quickapp-webview",  
    "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",  
    "build:quickapp-webview-union": "uni build -p quickapp-webview-union"  
  },  
  "dependencies": {  
    "@dcloudio/uni-app": "3.0.0-3090620231104002",  
    "@dcloudio/uni-app-plus": "3.0.0-3090620231104002",  
    "@dcloudio/uni-components": "3.0.0-3090620231104002",  
    "@dcloudio/uni-h5": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-alipay": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-baidu": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-jd": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-kuaishou": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-lark": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-qq": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-toutiao": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-weixin": "3.0.0-3090620231104002",  
    "@dcloudio/uni-mp-xhs": "3.0.0-3090620231104002",  
    "@dcloudio/uni-quickapp-webview": "3.0.0-3090620231104002",  
    "vue": "^3.2.45",  
    "vue-i18n": "^9.1.9"  
  },  
  "devDependencies": {  
    "@dcloudio/types": "^3.3.2",  
    "@dcloudio/uni-automator": "3.0.0-3090620231104002",  
    "@dcloudio/uni-cli-shared": "3.0.0-3090620231104002",  
    "@dcloudio/uni-stacktracey": "3.0.0-3090620231104002",  
    "@dcloudio/vite-plugin-uni": "3.0.0-3090620231104002",  
    "@vue/runtime-core": "^3.2.45",  
    "miniprogram-ci": "^1.9.8",  
    "vite": "3.2.7"  
  }  
}  
2023-11-16 14:04 负责人:无 分享
已邀请:
YUANRJ

YUANRJ

"type": "module"删掉,然后重新安装下依赖。

l***@163.com

l***@163.com

在不删除 "type": "module" 的情况下
由于 vite-plugin-uni 插件不兼容ESM
可以使用下面的方法过渡一下

import Uni from '@dcloudio/vite-plugin-uni'

export default defineConfig({
plugins: [
Uni.default()
]
})

要回复问题请先登录注册