반응형

 

이클립스..안드로이드....

 

jar 파일 import 했는데 적용이 안됐다

 

하나씩 확인해보자

 

1. jar 파일 까보면 .class 가 아닌 .java 로 되어있는지

2. libs 폴더에 넣고 해당 jar 파일 우클릭 -> build path -> add build path 했는지

3. 프로젝트 우클릭 -> properties -> Java Build Path -> Order and Export 에서 해당 jar 파일 체크 되어있는지

 

나는 마지막 3번.. import 시켜놧더니만 이클립스 툴 자체의 properties 에서 체크를 안해놔서 import가 안됐었다..

인텔리제이만 써가지고..;; 이런경우보니까 너무 당황스럽다 ㅠㅠ

 

참고로 Android private libraries 체크해제 안하면 에러뜬다; 쟤도 꼭 체크해제 해주길

728x90
반응형

 

그런일이 일어나서는 안되겠지만

혹시 이클립스로 안드로이드를 작업하는 일이 생긴다면...

 

아래와 같은 오류메세지를 볼수도있다

 

Android Dx Error1, Failed to convert to Dalvik format

 

그럴때는 프로젝트 우클릭 -> Properties -> Java Build Path -> Order and export 클릭

 

Android Private Libraries 체크를 해제해주자

 

728x90
반응형

 

 

react 프로젝트에서 svg를 import 시키고 컴포넌트를 아래와 같이 추가하였다

import {useRouter} from "next/router";

import GoogleSignIn from '@/assets/googleIcon.svg'

export const JoinGoogle = () => {

    function socialLoginGoogle() {
        ///////
    }

    return (
        <>
            <button onClick={socialLoginGoogle}>
                <GoogleSignIn />
                구글로 가입하기
            </button>
        </>
    )
}


별다른 문제가 없을거라 생각했는데, 오류가 발생하였다

 

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

 

터미널 로그에서는 <GoogleSignIn/>을 확인하라고 보여진다

 

Check your code at JoinGoogle.tsx:21.

 

확인해보니, svg파일을 사용하려면 별도의 플러그인을 install 해야한다고 함...

 

해결방법

 

1. install svgr webpack 

npm install -D @svgr/webpack

 

터미널에서 svgr webpack 을 다운받는다

 

2. next.config.js 수정

/** @type {import('next').NextConfig} */
const nextConfig = {

....
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    })
    return config
  },
  
  .....
}

module.exports = nextConfig

 

webpack 설정을 추가해준다

728x90
반응형

localhost:3000 이라는 포트로 만들어진 react 프로젝트에서

다른 포트번호로 실행된 백단 프로젝트를 연결할때 api cors error 를 필연적으로 만나게된다.

 

해결방법은 간단하다

 

1. next.config.js 수정

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false, //true 면 next dev 실행할때 useEffect 2번씩 실행
  swcMinify: true,
  eslint: {
    ignoreDuringBuilds: true,
  },
  compiler: {
    styledComponents: true,
  },
  images: {
    unoptimized: true,
    domains: ['picsum.photos', 'img.dmitory.com', 'image.edaily.co.kr'],
  },
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    })
    return config
  },
  //api cors 에러 프록시 설정
  async rewrites() {
    return [
      {
        source: '/api-aaa/:path*',
        destination: 'http://localhost:8080/api-aaa/:path*',
      },
      {
        source: '/api-bbb/:path*',
        destination: 'http://localhost:8090/api-bbb/:path*',
      },
      {
        source: '/api-ccc/:path*',
        destination: 'http://localhost:8443/api-ccc/:path*',
      },
      {
        source: '/upload/:path*',
        destination: 'http://localhost:8443/upload/:path*',
      },
    ]
  },
}

module.exports = nextConfig

 

 

rewrites 안쪽에 내가 통신하려고 하는 서버의 포트번호를 넣어주면 된다

나의 경우 멀티모듈을 사용했기때문에 저렇게 많은 포트가 필요했다

 

source 설정

지난 포스팅에 있는것처럼 api 호출할때 아래와 같은식으로 호출되는 부분이 있다고 한다면, 

getMenu = async ()=> {
    return await client.get('/api-aaa/menu/list')
}

 

/api-aaa/ 를 prefix로 삼고 api-aaa 로 통신하는 모든 uri들은 포트 8080으로 가게끔 경로를 틀어준다는 의미이다

 

destination 설정

만약 로컬에서 프론트/백단 소스를 모두 띄운다면 위 코드는 문제가 없겠지만

 

로컬에서 프론트 실행하고, 다른 서버에서 백단을  실행하거나

프론트/백단 소스코드를 모두 다른 서버(aws, linux 등..) 에서 실행한다면 destination 을 변경해야한다

...

async rewrites() {
    return [
      {
        source: '/api-aaa/:path*',
        destination: 'http://서버IP:8080/api-aaa/:path*',
      },
      {
        source: '/api-bbb/:path*',
        destination: 'http://서버IP:8090/api-bbb/:path*',
      },
      {
        source: '/api-ccc/:path*',
        destination: 'http://서버IP:8443/api-ccc/:path*',
      },
      {
        source: '/upload/:path*',
        destination: 'http://서버IP:8443/upload/:path*',
      },
    ]
  },

...

 

localhost 부분을 서버IP로 바꿔주면 된다.

 

 

2. 백단 소스코드수정

만약 WebConfig 를 설정하는 소스코드가 있다면 해당부분을 수정하고 없다면 새로만들어주자

@Configuration 으로 전체검색했을때 없으면 없는것

 

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${config.server-url}")
    String serverUrl;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://" + serverUrl + ":3000") // 프론트의 주소와 포트번호
                .allowedMethods("GET", "POST")
                .allowCredentials(true);
    }

}

 

 

나는 get 과 post만 열어줬고 이 설정만 추가하면 잘될것!!

 

혹시 allowedOrigins에 다른 ip주소도 추가해야한다면 아래와같이 콤마로 추가할수있다

.allowedOrigins("http://" + serverUrl + ":3000", "http://어쩌고ip:3000")

 

 

그래도 안된다면, spring security 사용하고있는경우 security 설정에서 막고있는게 아닌지 확인해야 한다.

 

그래도 안된다면!! IP주소 혹은 API PATH 오타가 있지는 않은지 확인해보자

728x90
반응형

 

 

 

 [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Cannot find module 'mini-css-extract-plugin/dist/CssDependency'

 

.next 의 cache 폴더 삭제

728x90

+ Recent posts