How to solve syntax error, unexpected token, export type?

Viewed 6102

I was using version 2.x of react-navigation, now I'm migrating to version 5.x. I have installed all modules according to the documentation, but on running the application, I get this error.

It seems more like a typescript compilation error, but I'm not sure why it appeared, as I simply ran npm install command and have not touched any node_module files.

error: SyntaxError: E:\PROJECTS\rnzone\BoxApp\node_modules\@react-navigation\stack\src\index.tsx: Unexpected token (51:12)

  49 |  * Types
  50 |  */
> 51 | export type {
     |             ^
  52 |   StackNavigationOptions,
  53 |   StackNavigationProp,
  54 |   StackHeaderProps,

What do you suggest?

3 Answers

So I was able to solve this by upgrading @babel/core and @babel/runtime in dev dependencies.

Support for type-only imports + exports was added in 7.9.0

Thanks to nickyleach for pointing this out.

If the above isn't working, add @babel/core as a global dependency (yarn global add @babel/core / npm install -g @babel/core), because globally-installed expo-cli won't recognize project-based babel installations for some reason.

Try the following steps to resolve the issue,

  • npm install @babel/core@^7.9.0
  • npm install @babel/runtime@^7.9.2
  • npm install typescript@^3.8.3
  • rm -rf node_modules
  • npm install
  • Uninstall app in emulator/phone.
  • npm start -- --reset-cache
Related