xioxin / taro-f2

Taro多端F2图表
107 stars 21 forks source link

引入 taro-f2/dist/weapp/common/f2-tool.ts 报语法错误 #52

Open 953133667 opened 4 years ago

953133667 commented 4 years ago

在 index.jsx 中引入 fixF2

import { fixF2 } from "taro-f2/dist/weapp/common/f2-tool.ts";

报错如下

./node_modules/taro-f2/dist/weapp/common/f2-tool.ts
Module build failed (from ./node_modules/@tarojs/mini-runner/node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/kedehua/projects_2020/ding-pt-school/node_modules/taro-f2/dist/weapp/common/f2-tool.ts: Unexpected token, expected "," (3:25)

  1 | import Taro from '@tarojs/taro'
  2 | 
> 3 | export function fixF2 (F2: any): any {
    |                          ^
  4 |   if( ( !F2 ) || F2.TaroFixed){return F2}
  5 |   if (process.env.TARO_ENV !== 'h5') {
  6 |     function strLen(str) {

我的项目是不支持ts ,请问各位大佬怎么解决?

liding1990 commented 3 years ago

在taro项目下安装typescript: npm install typescript

然后修改babel.config.js,设置ts: true

module.exports = {
  presets: [
    ['taro', {
      framework: 'react',
      ts: true
    }]
  ]
}