簡體   English   中英

Expo SDK 44 升級錯誤 - App.js: [BABEL]: Unexpected token '.'

[英]Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.'

我最近將我的應用程序從 SDK 40 升級到 SDK 44 並遇到了這個錯誤 App.js: [BABEL]: Unexpected token '.' (處理時:/Users/user/path/to/project/node_modules/babel-preset-expo/index.js)

錯誤堆棧跟蹤:

App.js: [BABEL]: Unexpected token '.' (While processing: /Users/user/path/to/project/node_modules/babel-preset-expo/index.js)
/Users/user/path/to/project/node_modules/babel-preset-expo/index.js:48
        ...(options?.jsxRuntime !== 'classic' && {
                    ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:931:16)
    at Module._compile (internal/modules/cjs/loader.js:979:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at loadCjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:85:18)
    at loadCjsOrMjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:57:16)

這是我的 babel.config.js:

return {
    presets: ['babel-preset-expo', { jsxRuntime: 'automatic' }],
    plugins: [
        ['inline-dotenv'],
        ['.....']
    ]
}

這是我的 package.json:

{
    "main": "node_modules/expo/AppEntry.js",
    "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "web": "expo start --web",
        "eject": "expo eject",
        "test": "jest"
    },
    "jest": {
        "preset": "jest-expo"
    },
    "dependencies": {
        "@babel/plugin-transform-react-jsx": "^7.16.5",
        "@react-native-async-storage/async-storage": "~1.15.0",
        "@react-native-community/art": "^1.2.0",
        "@react-native-community/datetimepicker": "4.0.0",
        "@react-native-community/masked-view": "0.1.10",
        "@react-native-community/netinfo": "7.1.3",
        "@react-native-community/push-notification-ios": "^1.2.2",
        "@react-native-community/slider": "4.1.12",
        "@react-navigation/native": "^5.1.4",
        "aws-amplify": "^3.3.1",
        "aws-amplify-react-native": "^4.2.6",
        "axios": "^0.19.2",
        "expo": "^44.0.0",
        "expo-app-loading": "~1.3.0",
        "expo-barcode-scanner": "~11.2.0",
        "expo-camera": "~12.1.0",
        "expo-constants": "~13.0.0",
        "expo-font": "~10.0.4",
        "expo-linking": "~3.0.0",
        "expo-mail-composer": "~11.1.0",
        "expo-notifications": "~0.14.0",
        "expo-permissions": "~13.1.0",
        "expo-secure-store": "~11.1.0",
        "expo-sqlite": "~10.1.0",
        "expo-updates": "~0.11.2",
        "expo-web-browser": "~10.1.0",
        "file-saver": "^2.0.2",
        "jsbarcode": "^3.11.3",
        "link": "^0.1.5",
        "metro-config": "^0.64.0",
        "npm": "^8.3.0",
        "qs": "^6.9.4",
        "react": "17.0.1",
        "react-dom": "17.0.1",
        "react-native": "https://github.com/expo/react-native/archive/sdk-44.0.0.tar.gz",
        "react-native-barcode-expo": "^1.1.1",
        "react-native-elements": "^3.2.0",
        "react-native-fs": "^2.16.6",
        "react-native-gesture-handler": "~2.1.0",
        "react-native-modal": "^11.5.6",
        "react-native-modal-datetime-picker": "^8.6.0",
        "react-native-paper": "^3.10.1",
        "react-native-push-notification": "^3.5.2",
        "react-native-reanimated": "~2.3.1",
        "react-native-router-flux": "^4.2.0",
        "react-native-safe-area-context": "3.3.2",
        "react-native-screens": "~3.10.1",
        "react-native-snap-carousel": "^3.9.1",
        "react-native-svg": "12.1.1",
        "react-native-web": "0.17.1",
        "react-navigation-animated-switch": "^0.6.4",
        "react-navigation-drawer": "^2.4.11",
        "react-navigation-header-buttons": "^3.0.5",
        "react-router-dom": "^6.0.0-alpha.3",
        "yarn": "^1.22.17"
    },
    "devDependencies": {
        "@babel/core": "^7.12.9",
        "@babel/runtime": "^7.9.2",
        "@react-native-community/eslint-config": "^0.0.7",
        "babel-jest": "^25.1.0",
        "babel-plugin-inline-dotenv": "^1.6.0",
        "babel-preset-expo": "9.0.1",
        "eslint": "^6.8.0",
        "expo-cli": "^5.0.2",
        "jest": "^26.6.3",
        "jest-expo": "^44.0.0",
        "metro-react-native-babel-preset": "^0.66.2",
        "react-test-renderer": "^16.13.1"
    },
    "private": true
}

任何幫助將不勝感激。

你能給你的嗎

  • package.json
  • 節點版本

我認為這是因為 babel 問題/您的節點版本,因為它無法轉換可選鏈接https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

也許嘗試使用最新的 LTS 節點版本? 因為據我所知,最新的 LTS 節點版本已經支持可選鏈

據我所知,Expo SDK 44 仍處於測試階段。

錯誤堆棧跟蹤讀取更新的語法(在這種情況下是可選的鏈接運算符?。)沒有被 Babel 轉譯,這會導致失敗。

只需降級到穩定的 SDK 43 即可解決所有問題。

PS:這個錯誤已經被beta測試人員報告給Expo。

只是讓您知道,當您使用 Node 12 時,這是babel-preset-expo中的一個錯誤。

node12 不支持可選鏈接,可以很容易地用額外的檢查替換

https://github.com/expo/expo/pull/15545

降級到 SDK 43.0.0 對我來說效果很好:

expo update 43.0.0

如果您使用 expo v44,您必須將babel-preset-expo開發依賴更新到 v9.0.2:

"babel-preset-expo": "9.0.2",

從 API 獲取數據並記錄它時出現此錯誤“SyntaxError: Unexpected token '<',”<div id="text_translate"><p> 從 API 獲取數據並記錄它時出現此錯誤“SyntaxError: Unexpected token '<', "<.DOCTYPE "... is not valid JSON at App:js:24:1"</p><p> <strong>應用程序.js</strong></p><pre> import { useState } from "react"; import "./App.css"; import CurrentWeather from "./component/current-weather/current-weather"; import { WEATHER_API_KEY, WEATHER_API_URL } from "./component/search/api"; import Search from "./component/search/search"; function App() { const [currentWeather, setCurrentWeather] = useState(null); const [forecast, setForecast] = useState(null); const handleOnSearchChange = (searchData) => { const [lat, lon] = searchData.value.split(" "); const currentWeatherFetch = fetch( `${WEATHER_API_URL}/weather?lat=${lat}&lon=${lon}&appid=${WEATHER_API_KEY}` ); const forecastFetch = fetch( `${WEATHER_API_URL}/forecast?lat=${lat}&lon={${lon}&appid=${WEATHER_API_KEY}` ); Promise.all([currentWeatherFetch, forecastFetch]).then(async (response) => { const weatherResponse = await response[0].json(); const forcastResponse = await response[1].json(); setCurrentWeather({ city: searchData.label, ...weatherResponse, }); setForecast({ city: searchData.label, ...forcastResponse }); }).catch(console.log); }; console.log(currentWeather); console.log(forecast); return ( <div className="container"> <Search onSearchChange={handleOnSearchChange} /> <CurrentWeather /> </div> ); } export default App;</pre><p> <strong>api.js</strong></p><pre> export const geoApiOptions = { method: "GET", headers: { "X-RapidAPI-Key": process.env.REACT_APP_GEODB_API_KEY, "X-RapidAPI-Host": "wft-geo-db.p.rapidapi.com", }, }; export const GEO_API_URL = "https://wft-geo-db.p.rapidapi.com/v1/geo"; export const WEATHER_API_URL = "api.openweathermap.org/data/2.5"; export const WEATHER_API_KEY = process.env.REACT_APP_WEATHER_API_KEY;</pre><p> 我在瀏覽器中手動給出了 api 鏈接並得到了這個結果https://api.openweathermap.org/data/2.5/weather?lat=-27.47&lon=153.12&appid=<API_KEY></p><pre> {"coord":{"lon":153.12,"lat":-27.47},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":{"temp":296.36,"feels_like":296.75,"temp_min":295.22,"temp_max":297.15,"pressure":1016,"humidity":77},"visibility":10000,"wind":{"speed":3.6,"deg":120},"clouds":{"all":75},"dt":1673616299,"sys":{"type":1,"id":9485,"country":"AU","sunrise":1673550242,"sunset":1673599638},"timezone":36000,"id":2176264,"name":"Belmont","cod":200}</pre><p> 在獲得響應而不是響應時出現錯誤。 不確定我在這里做錯了什么。</p><p> 在獲得響應而不是響應時出現錯誤。</p><p> 從評論中得到了如何獲得整個回復的建議,這是我得到的,</p><pre> <.DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="/favicon,ico" /> <meta name="viewport" content="width=device-width. initial-scale=1" /> <meta name="theme-color" content="#000000" /> <meta name="description" content="Web site created using create-react-app" /> <link rel="apple-touch-icon" href="/logo192.png" /> <.-- manifest:json provides metadata used when your web app is installed on a user's mobile device or desktop. See https.//developers.google.com/web/fundamentals/web-app-manifest/ --> <link rel="manifest" href="/manifest.json" /> <.-- Notice the use of in the tags above. It will be replaced with the URL of the `public` folder during the build. Only files inside the `public` folder can be referenced from the HTML, Unlike "/favicon.ico" or "favicon.ico". "/favicon.ico" will work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> <title>React App</title> <script defer src="/static/js/bundle,js"></script></head> <body> <noscript>You need to enable JavaScript to run this app.</noscript> <div id="root"></div> <,-- This HTML file is a template, If you open it directly in the browser. you will see an empty page. You can add webfonts, meta tags. or analytics to this file, The build step will place the bundled scripts into the <body> tag. To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> </body> </html></pre><p> 沒有任何相關的錯誤</p></div>

[英]While fetching data from API and logging it getting this error "SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON at App.js:24:1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 ReactJS:語法錯誤:src / App.js:意外令牌(16:6) 從 Babel 5.8.35 升級到 6.0.0 不會編譯帶有 SyntaxError 和意外令牌的 app.js app.js:1 �� SyntaxError: Invalid or unexpected token 我找不到錯誤,它顯示為“Error in./src/App.js Syntax error: Unexpected token (11:5)” 反應錯誤-./src/App.js第16行:解析錯誤:意外的令牌 將 App.Js 導入節點時的 BABEL_PARSE_ERROR Post 500 (Internal Server Error) line 48 app.js 和錯誤 SyntaxError: Unexpected token &lt; in JSON at position 0 line 65 in app.js 從 API 獲取數據並記錄它時出現此錯誤“SyntaxError: Unexpected token '<',”<div id="text_translate"><p> 從 API 獲取數據並記錄它時出現此錯誤“SyntaxError: Unexpected token '<', "<.DOCTYPE "... is not valid JSON at App:js:24:1"</p><p> <strong>應用程序.js</strong></p><pre> import { useState } from "react"; import "./App.css"; import CurrentWeather from "./component/current-weather/current-weather"; import { WEATHER_API_KEY, WEATHER_API_URL } from "./component/search/api"; import Search from "./component/search/search"; function App() { const [currentWeather, setCurrentWeather] = useState(null); const [forecast, setForecast] = useState(null); const handleOnSearchChange = (searchData) => { const [lat, lon] = searchData.value.split(" "); const currentWeatherFetch = fetch( `${WEATHER_API_URL}/weather?lat=${lat}&lon=${lon}&appid=${WEATHER_API_KEY}` ); const forecastFetch = fetch( `${WEATHER_API_URL}/forecast?lat=${lat}&lon={${lon}&appid=${WEATHER_API_KEY}` ); Promise.all([currentWeatherFetch, forecastFetch]).then(async (response) => { const weatherResponse = await response[0].json(); const forcastResponse = await response[1].json(); setCurrentWeather({ city: searchData.label, ...weatherResponse, }); setForecast({ city: searchData.label, ...forcastResponse }); }).catch(console.log); }; console.log(currentWeather); console.log(forecast); return ( <div className="container"> <Search onSearchChange={handleOnSearchChange} /> <CurrentWeather /> </div> ); } export default App;</pre><p> <strong>api.js</strong></p><pre> export const geoApiOptions = { method: "GET", headers: { "X-RapidAPI-Key": process.env.REACT_APP_GEODB_API_KEY, "X-RapidAPI-Host": "wft-geo-db.p.rapidapi.com", }, }; export const GEO_API_URL = "https://wft-geo-db.p.rapidapi.com/v1/geo"; export const WEATHER_API_URL = "api.openweathermap.org/data/2.5"; export const WEATHER_API_KEY = process.env.REACT_APP_WEATHER_API_KEY;</pre><p> 我在瀏覽器中手動給出了 api 鏈接並得到了這個結果https://api.openweathermap.org/data/2.5/weather?lat=-27.47&lon=153.12&appid=<API_KEY></p><pre> {"coord":{"lon":153.12,"lat":-27.47},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":{"temp":296.36,"feels_like":296.75,"temp_min":295.22,"temp_max":297.15,"pressure":1016,"humidity":77},"visibility":10000,"wind":{"speed":3.6,"deg":120},"clouds":{"all":75},"dt":1673616299,"sys":{"type":1,"id":9485,"country":"AU","sunrise":1673550242,"sunset":1673599638},"timezone":36000,"id":2176264,"name":"Belmont","cod":200}</pre><p> 在獲得響應而不是響應時出現錯誤。 不確定我在這里做錯了什么。</p><p> 在獲得響應而不是響應時出現錯誤。</p><p> 從評論中得到了如何獲得整個回復的建議,這是我得到的,</p><pre> <.DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="/favicon,ico" /> <meta name="viewport" content="width=device-width. initial-scale=1" /> <meta name="theme-color" content="#000000" /> <meta name="description" content="Web site created using create-react-app" /> <link rel="apple-touch-icon" href="/logo192.png" /> <.-- manifest:json provides metadata used when your web app is installed on a user's mobile device or desktop. See https.//developers.google.com/web/fundamentals/web-app-manifest/ --> <link rel="manifest" href="/manifest.json" /> <.-- Notice the use of in the tags above. It will be replaced with the URL of the `public` folder during the build. Only files inside the `public` folder can be referenced from the HTML, Unlike "/favicon.ico" or "favicon.ico". "/favicon.ico" will work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> <title>React App</title> <script defer src="/static/js/bundle,js"></script></head> <body> <noscript>You need to enable JavaScript to run this app.</noscript> <div id="root"></div> <,-- This HTML file is a template, If you open it directly in the browser. you will see an empty page. You can add webfonts, meta tags. or analytics to this file, The build step will place the bundled scripts into the <body> tag. To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> </body> </html></pre><p> 沒有任何相關的錯誤</p></div> app.js 中的 Expo 自定義 fonts 和 BottomTabNavigator Next.js _app.js:模塊解析失敗:新項目上的意外令牌
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM