Code Monkey home page Code Monkey logo

Comments (11)

jasper-ops avatar jasper-ops commented on June 20, 2024 1

我的状况似乎不太一样,当在package.json中指定type 为 commnjs时,项目启动报错:TypeError: Uni is not a function。 跑不起来,我尝试了了下修改为:

plugins: [
      uni.default(), 
// 后面省略

这样就能够运行了,不知道对不对。 备注:已经修改vite.config.ts文件名为vite.config.mts

不要改成mts呀,改成mts就会用esm去解析了,uni的插件不是esm的,它是cjs的

from uni-app.

qinains avatar qinains commented on June 20, 2024

升级unocss到0.59.0版本之后,报这个错

from uni-app.

StrivingRabbit avatar StrivingRabbit commented on June 20, 2024

升级unocss到0.59.0版本之后,报这个错

建议先使用 0.58.x

from uni-app.

jasper-ops avatar jasper-ops commented on June 20, 2024

目前@dcloudio/vite-plugin-uni采用的是commonJS的方式,而unocss0.59.x已经不支持commonjs了,仅仅支持ESM,所以目前挺尴尬的,当你用不支持cjs的库时,大概率就用不了了,不知道各位大佬有什么解决方案;

from uni-app.

jasper-ops avatar jasper-ops commented on June 20, 2024

找到一个新办法,使用动态导入来导入不支持cjs的模块,但是你的package.json的type还是要设置成commnjs,因为uniapp的插件还是cjs的
PixPin_2024-05-04_23-15-11

from uni-app.

zxhbloomer avatar zxhbloomer commented on June 20, 2024

我的状况似乎不太一样,当在package.json中指定type 为 commnjs时,项目启动报错:TypeError: Uni is not a function。
跑不起来,我尝试了了下修改为:

plugins: [
      uni.default(), 
// 后面省略

这样就能够运行了,不知道对不对。
备注:已经修改vite.config.ts文件名为vite.config.mts

from uni-app.

zxhbloomer avatar zxhbloomer commented on June 20, 2024

确实如此,需要cjs能够搞定。

from uni-app.

zxhbloomer avatar zxhbloomer commented on June 20, 2024

升级后的部分问题:
vite.config.ts修改成vite.config.mts:Uni is not a function。
vite.config.ts修改成vite.config.cjs:h5可以,app运行不起来
vite.config.mts改回ts:h5和app可以运行,但是页面中引用的uni_modules\uview-ui\components,都不能正确解析,

例如:在页面vue中使用<u-divider>,运行后,在chrome查看html代码,发现代码是<u-divider>,没有正确解析。easycom没有更改过。

from uni-app.

aboutZZ avatar aboutZZ commented on June 20, 2024

【Workaround】
在uniapp没修复此问题前,暂时先这样把

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

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

from uni-app.

jasper-ops avatar jasper-ops commented on June 20, 2024

from uni-app.

shijunti19 avatar shijunti19 commented on June 20, 2024

官方什么时候解决啊,全部改成esm啊

from uni-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.