Unexpected token ‘export’ (意外的令牌 ‘export’)

huangapple go评论104阅读模式
英文:

node_modules\expo\AppEntry.js: Unexpected token 'export'

问题

I have expo project and i use tamagui and react-native. I am working with Github. When I run npm uninstall expo-font, I got node_modules\expo\AppEntry.js: Unexpected token 'export' issue and f in YStack and jc in Paragraph give error.

f error: Type '{ children: Element[]; f: number; jc: string; ai: string; backgroundColor: "$backgroundSoft"; }' is not assignable to type 'IntrinsicAttributes & Omit<ViewProps, "display" | "children" | "style" | "onLayout" | keyof GestureResponderHandlers> & ... 10 more ... & RefAttributes<...>'.
Property 'f' does not exist on type 'IntrinsicAttributes & Omit<ViewProps, "display" | "children" | "style" | "onLayout" | keyof GestureResponderHandlers> & ... 10 more ... & RefAttributes<...>'. jc error: Type 'string' is not assignable to type 'undefined'.ts(2322)

As far as I know, terms like f and jc are defined in Tamagui's own tokens by default.
My codes:

This is App.tsx:

import { useFonts } from "expo-font";
import React from "react";
import { StatusBar } from "expo-status-bar";
import { useColorScheme } from "react-native";
import { Paragraph, TamaguiProvider, Theme, YStack } from "tamagui";
import config from "./tamagui.config";

export default function App() {
 const colorScheme = useColorScheme();
 const [loaded] = useFonts({
    Urbanist: require("./assets/fonts/Urbanist-Bold.otf"),
    UrbanistSemibold: require("./assets/fonts/Urbanist-SemiBold.otf"),
    UrbanistMedium: require("./assets/fonts/Urbanist-Medium.otf"),
    UrbanistRegular: require("./assets/fonts/Urbanist-Regular.otf"),
  });
 if (!loaded) {
    return null;
  }
  return (
    <TamaguiProvider config={config}>
      <Theme name={colorScheme === "dark" ? "dark" : "light"}>
        <YStack
          f={1}
          jc="center"
          ai="center"
          backgroundColor="$backgroundSoft"
        >
          <Paragraph color="$color" jc="center">
            {colorScheme}
          </Paragraph>
          <StatusBar style="auto" />
        </YStack>
      </Theme>
    </TamaguiProvider>
  );
}

This is package.json:

"dependencies": {
    "@tamagui/animations-react-native": "^1.43.13",
    "@tamagui/babel-plugin": "^1.43.13",
    "@tamagui/config": "^1.43.13",
    "@tamagui/font-inter": "^1.43.13",
    "@tamagui/theme-base": "^1.43.13",
    "babel-plugin-transform-inline-environment-variables": "^0.4.4",
    "expo": "~48.0.18",
    "expo-font": "~11.1.1",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-dom": "^18.2.0",
    "react-native": "0.71.8",
    "react-native-reanimated": "~2.14.4",
    "react-native-web": "^0.19.6",
    "tamagui": "^1.43.13"
},
"devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.0.14",
    "@typescript-eslint/eslint-plugin": "^5.62.0",
    "eslint": "^8.46.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-config-standard-with-typescript": "^37.0.0",
    "eslint-plugin-import": "^2.28.0",
    "eslint-plugin-n": "^16.0.1",
    "eslint-plugin-prettier": "^5.0.0",
    "eslint-plugin-promise": "^6.1.1",
    "eslint-plugin-react": "^7.33.1",
    "husky": "^8.0.3",
    "prettier": "3.0.1",
    "typescript": "^4.9.5"
},
"private": true,
"lint-staged": {
    "*.{ts,js,jsx,tsx}": [
        "eslint --ignore-path .gitignore --fix --max-warnings 0",
        "prettier --ignore-path .gitignore --write"
    ]
}
}

I deleted node_modules and reinstalled but it didn't work. I run npx expo install expo-font but it didn't work. I cleared the cache(npm cache clean --force ) but it didn't work. I merged main and theme branches.

英文:

I have expo project and i use tamagui and react-native.I am working with Github. When I run npm uninstall expo-font, I got node_modules\expo\AppEntry.js: Unexpected token &#39;export&#39; issue and f in YStack and jc in Paragraph give error.

f error :  Type &#39;{ children: Element[]; f: number; jc: string; ai: string; backgroundColor: &quot;$backgroundSoft&quot;; }&#39;** is not assignable to type **&#39;IntrinsicAttributes &amp; Omit&lt;ViewProps, &quot;display&quot; | &quot;children&quot; | &quot;style&quot; | &quot;onLayout&quot; | keyof GestureResponderHandlers&gt; &amp; ... 10 more ... &amp; RefAttributes&lt;...&gt;&#39;.**
Property &#39;f&#39; does not exist on type **&#39;IntrinsicAttributes &amp; Omit&lt;ViewProps, &quot;display&quot; | &quot;children&quot; | &quot;style&quot; | &quot;onLayout&quot; | keyof GestureResponderHandlers&gt; &amp; ... 10 more ... &amp; RefAttributes&lt;...&gt;&#39;**.    jc error :  Type &#39;string&#39; is not assignable to type **&#39;undefined&#39;.ts(2322)**

As far as I know, terms like f and jc are defined in Tamagui's own tokens by default.
My codes :
This is App.tsx:

import { useFonts } from &quot;expo-font&quot;
import React from &quot;react&quot;
import { StatusBar } from &quot;expo-status-bar&quot;
import { useColorScheme } from &quot;react-native&quot;
import { Paragraph, TamaguiProvider, Theme, YStack } from &quot;tamagui&quot;
import config from &quot;./tamagui.config&quot;
export default function App() {
 const colorScheme = useColorScheme()
 const [loaded] = useFonts({
    Urbanist: require(&quot;./assets/fonts/Urbanist-Bold.otf&quot;),
    UrbanistSemibold: require(&quot;./assets/fonts/Urbanist-SemiBold.otf&quot;),
    UrbanistMedium: require(&quot;./assets/fonts/Urbanist-Medium.otf&quot;),
    UrbanistRegular: require(&quot;./assets/fonts/Urbanist-Regular.otf&quot;),
  })
 if (!loaded) {
    return null
  }
  return (
    &lt;TamaguiProvider config={config}&gt;
      &lt;Theme name={colorScheme === &quot;dark&quot; ? &quot;dark&quot; : &quot;light&quot;}&gt;
        &lt;YStack
          f={1}
          jc=&quot;center&quot;
          ai=&quot;center&quot;
          backgroundColor={&quot;$backgroundSoft&quot;}
        &gt;
          &lt;Paragraph color=&quot;$color&quot; jc=&quot;center&quot;&gt;
            {colorScheme}
          &lt;/Paragraph&gt;
          &lt;StatusBar style=&quot;auto&quot; /&gt;
        &lt;/YStack&gt;
      &lt;/Theme&gt;
    &lt;/TamaguiProvider&gt;
  )
}

This is package.json:

    &quot;dependencies&quot;: {
    &quot;@tamagui/animations-react-native&quot;: &quot;^1.43.13&quot;,
    &quot;@tamagui/babel-plugin&quot;: &quot;^1.43.13&quot;,
    &quot;@tamagui/config&quot;: &quot;^1.43.13&quot;,
    &quot;@tamagui/font-inter&quot;: &quot;^1.43.13&quot;,
    &quot;@tamagui/theme-base&quot;: &quot;^1.43.13&quot;,
    &quot;babel-plugin-transform-inline-environment-variables&quot;: &quot;^0.4.4&quot;,
    &quot;expo&quot;: &quot;~48.0.18&quot;,
    &quot;expo-font&quot;: &quot;~11.1.1&quot;,
    &quot;expo-status-bar&quot;: &quot;~1.4.4&quot;,
    &quot;react&quot;: &quot;18.2.0&quot;,
    &quot;react-dom&quot;: &quot;^18.2.0&quot;,
    &quot;react-native&quot;: &quot;0.71.8&quot;,
    &quot;react-native-reanimated&quot;: &quot;~2.14.4&quot;,
    &quot;react-native-web&quot;: &quot;^0.19.6&quot;,
    &quot;tamagui&quot;: &quot;^1.43.13&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@babel/core&quot;: &quot;^7.20.0&quot;,
    &quot;@types/react&quot;: &quot;~18.0.14&quot;,
    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^5.62.0&quot;,
    &quot;eslint&quot;: &quot;^8.46.0&quot;,
    &quot;eslint-config-prettier&quot;: &quot;^9.0.0&quot;,
    &quot;eslint-config-standard-with-typescript&quot;: &quot;^37.0.0&quot;,
    &quot;eslint-plugin-import&quot;: &quot;^2.28.0&quot;,
    &quot;eslint-plugin-n&quot;: &quot;^16.0.1&quot;,
    &quot;eslint-plugin-prettier&quot;: &quot;^5.0.0&quot;,
    &quot;eslint-plugin-promise&quot;: &quot;^6.1.1&quot;,
    &quot;eslint-plugin-react&quot;: &quot;^7.33.1&quot;,
    &quot;husky&quot;: &quot;^8.0.3&quot;,
    &quot;prettier&quot;: &quot;3.0.1&quot;,
    &quot;typescript&quot;: &quot;^4.9.5&quot;
  },
  &quot;private&quot;: true,
  &quot;lint-staged&quot;: {
    &quot;*.{ts,js,jsx,tsx}&quot;: [
      &quot;eslint --ignore-path .gitignore --fix --max-warnings 0&quot;,
      &quot;prettier --ignore-path .gitignore --write&quot;
    ]
  }
}

I deleted node_modules and reinstalled but it didn't work.
I run npx expo install expo-font but it didn't work
I cleared the cache(npm cache clean --force ) but it didn't work.
I merged main and theme branches.

答案1

得分: 0

如果在 tamagui.config.ts 文件中写入 type TamaguiCustomConfig = AppConfig,则替换为 interface TamaguiCustomConfig extends AppConfig {} 并输入以下eslint注释行:

// eslint-disable-next-line @typescript-eslint/no-empty-interface
英文:

If type TamaguiCustomConfig = AppConfig is written in tamagui.config.ts file, replace it with interface TamaguiCustomConfig extends AppConfig {} and enter

> // eslint-disable-next-line @typescript-eslint/no-empty-interface as
eslint comment line.

huangapple
  • 本文由 发表于 2023年8月10日 14:46:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76873208.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定