Taro安装tailwindcss的异常报错

官方教程使用 Tailwind CSS | Taro 文档

按照官方流程一步一步操作下来,会报错

如果你选的是Vite会出现下面报错

taro Error: Cannot find module ‘webpack’

安装就能解决

yarn add webpack

npm i webpack

然后继续运行,依然报错

ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: E:\项目0528\taro-first\src\app.ts: Unexpected token, expected “,” (5:25)

3 | import ‘./app.scss’
4 |

5 | function App({ children }: PropsWithChildren) {
| ^
6 | useLaunch(() => {
7 | })
8 |
at parser.next ()
at normalizeFile.next ()
at run.next ()
at transform.next ()

→ Watching… [2024/7/30 16:47:25]

node:internal/process/promises:389
new UnhandledPromiseRejection(reason);
^

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason “[object Array]”.
at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
at processPromiseRejections (node:internal/process/promises:470:17)
at processTicksAndRejections (node:internal/process/task_queues:96:32) {
code: ‘ERR_UNHANDLED_REJECTION’
}

Node.js v20.15.0
error Command failed with exit code 1.

大概看出是webpack不解析typescript,尝试安装飘红的tsconfig-paths-webpack-plugin,应用

webpackChain(chain) {
    chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
    chain.merge({
      plugin: {
        install: {
          plugin: UnifiedWebpackPluginV5,
          args: [
            {
              appType: 'taro',
              // disabled: WeappTailwindcssDisabled,
              rem2rpx: true
            }
          ]
        }
      }
    });
  }

依旧没用,正确方式,打开babel.config.js,注解compiler这行👇

// babel.config.js
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
  presets: [
    ['taro', {
      framework: 'react',
      ts: true,
      // compiler: 'vite',
    }]
  ]
}

chain.resolve.plugin(‘tsconfig-paths’).use(TsconfigPathsPlugin)删不删都无所谓
此时应该可以正常运行了

<Text className=" text-base text-red-300">哈哈哈</Text>

如果出现下面这个

页面【pages/index/index]错误:
Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: E:\项目0528\taro-first\src\pages\index\index.tsx: Unexpected token, expected “,” (12:29)

微信小程序 👉 详情 👉 本地设置 👉 勾选将JS编译成ES5

  • 21
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你熬夜了吗?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值