React Native

[React Native] react-native-linear-gradient : Module parse failed: Unexpected token (8:36)

도우 2024. 8. 26. 17:09
반응형

CLI 환경에서 linear-gradient 라이브러리를 설치하고, web과 android 두 OS를 모두 빌드하는 과정에서 다음과 같은 에러가 발생했다

Module parse failed: Unexpected token (8:36)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

react-native-linear-gradient는 주로 모바일 환경에서 사용되기에 TypeScript 주석을 Webpack이 처리하지 못해서 발생하는 문제라고 한다.

해결방법은 간단하다

웹 환경에서 react-native-linear-gradient를 사용하지 않도록 설정해주면 된다.

webpack.config.js를 수정해서 웹 환경에서는 react-native-linear-gradient 대신 react-native-web-linear-gradient를 사용하도록 해주자.

resolve: {
  extensions: ['.web.js', '.js', '.jsx', '.ts', '.tsx', '.json'],
  alias: {
    'react-native$': 'react-native-web',
    'react-native-linear-gradient': 'react-native-web-linear-gradient', // 웹에서는 react-native-web-linear-gradient 사용
  },
},
반응형