【问题标题】:Keep getting "SyntaxError: Unexpected token 'export'" - what can i do/ what is going wrong?不断收到“SyntaxError: Unexpected token 'export'” - 我能做什么/出了什么问题?
【发布时间】:2021-01-05 22:45:57
【问题描述】:

我不断收到此错误。我尝试了多个不同的 node.js 版本(12、13、14),但仍然出现错误。我也尝试使用 val 而不是 import,但没有奏效。

这是我的代码:

import {createAppContainer } from 'react-navigation'
import {createStackNavigator } from 'react-navigation-stack'
import SearchScreen from './src/screens/SearchScreen'
    
const navigator = createStackNavigator({
        Search: SearchScreen
    },
    {
        initialRouteName: 'Search',
        defaultNavigationOptions: {
        title: 'Business Search'
    }
})
    
export default createAppContainer(navigator)

这是错误:

/Users/macbook/Downloads/food-boilerplate/node_modules/react-navigation/src/index.js:1
export * from '@react-navigation/core';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at [stdin]:7:24
    at Script.runInThisContext (vm.js:133:18)
    at Object.runInThisContext (vm.js:310:38)
[Finished in 0.427s]

非常感谢任何帮助 - 我已经尝试解决这个问题超过 5 个小时了。

谢谢:)

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"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.6",
    "axios": "^0.21.1",
    "babel": "^6.23.0",
    "expo": "^37.0.0",
    "react": "16.9.0",
    "react-dom": "16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-reanimated": "~1.7.0",
    "react-native-safe-area-context": "0.7.3",
    "react-native-screens": "~2.2.0",
    "react-navigation": "^4.4.3",
    "react-navigation-stack": "^2.10.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "babel-preset-expo": "^8.3.0"
  },
  "private": true
}

【问题讨论】:

  • 你有什么版本的 react-navigation ?
  • 17.0.1 :) 谢谢你的帮助。
  • 是 react-navigation 的版本 1 吗?你能显示package.json吗
  • 哦,我的错,我以为你的意思是反应版本。它应该是最新版本(5?),因为我几天前才安装它。
  • 我会将json添加到问题中

标签: javascript node.js reactjs react-native export


【解决方案1】:

这是我为 React Navigation 导入的样子:

import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";

我正在使用官方文档中提供的那些。我不知道这是否有什么不同,但请看一下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-25
    • 2020-12-27
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多