• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

antd ui라이브러리를 사용하니까 Cannot use import statement outside a module 에러가 나옵니다.

24.04.27 23:02 작성 24.04.27 23:02 수정 조회수 91

0

안녕하세요 제로초님

antd 라이브러리를 사용하니까

Server Error

SyntaxError: Cannot use import statement outside a module

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Call Stack

<unknown>

file:///C:/Users/%EC%A0%95%EC%9A%A9%EC%B1%84/Desktop/%EA%B3%B5%EB%B6%80/%EA%B0%95%EC%9D%98/react-nodebird/prepare/front/node_modules/rc-util/es/hooks/useMemo.js (1)

Next.js

rc-util/es/hooks/useMemo

file:///C:/Users/%EC%A0%95%EC%9A%A9%EC%B1%84/Desktop/%EA%B3%B5%EB%B6%80/%EA%B0%95%EC%9D%98/react-nodebird/prepare/front/.next/server/pages/index.js (8862:18)

Next.js

eval

/node_modules/antd/es/config-provider/index.js

./node_modules/antd/es/config-provider/index.js

file:///C:/Users/%EC%A0%95%EC%9A%A9%EC%B1%84/Desktop/%EA%B3%B5%EB%B6%80/%EA%B0%95%EC%9D%98/react-nodebird/prepare/front/.next/server/vendor-chunks/antd.js (570:1)

Next.js

eval

/node_modules/antd/es/grid/col.js

 

이러한 에러들이 나왔고 검색해보니
next.config.js 파일에

const nextConfig = {
	/* config options here */
	// reactStrictMode: true,
	swcMinify: true,
	transpilePackages: [
		"antd",
		"@ant-design",
		"rc-util",
		"rc-pagination",
		"rc-picker",
		"rc-notification",
		"rc-tooltip",
	],
	compiler: {
		styledComponents: true,
	},
};

module.exports = nextConfig;

이런식으로 넣어주면 괜찮다는 것을 보고

실행해보니 정상적으로 나오는것을 확인했습니다.

그런데 이제는

 

Warning: findDOMNode is deprecated and will be removed in the next major release. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here:
이런 에러가 나오고 있는데요..

원래 antd최신버전을 쓰고 있다가

깃헙의 제로초님과 동일하게 ^5.8.3" 버전으로 수정해봤는데도 동일한 이슈가 발생하더라구요

혹시 다른 부분을 수정해야할지 알 수 있을까해서

차장보다 문의 드립니다.

참고로 현재 package.json은

{
	"name": "react-nodebird",
	"version": "1.0.0",
	"description": "",
	"main": "index.js",
	"scripts": {
		"dev": "next dev",
		"build": "next build",
		"start": "next start"
	},
	"author": "",
	"license": "MIT",
	"dependencies": {
		"@ant-design/icons": "^5.3.6",
		"@reduxjs/toolkit": "^2.2.3",
		"antd": "^5.8.3",
		"next": "^14.2.3",
		"next-redux-wrapper": "^8.1.0",
		"react": "^18.3.1",
		"react-dom": "^18.3.1",
		"react-hook-form": "^7.51.3",
		"react-redux": "^9.1.1",
		"react-slick": "^0.30.2",
		"redux": "^5.0.1",
		"styled-components": "^6.1.8"
	},
	"devDependencies": {
		"eslint": "^8.57.0",
		"eslint-plugin-import": "^2.29.1",
		"eslint-plugin-react": "^7.34.1",
		"eslint-plugin-react-hooks": "^4.6.2"
	}
}


이렇습니다.

감사합니다.

답변 3

·

답변을 작성해보세요.

0

챠챠_님의 프로필

챠챠_

질문자

2024.04.28

답변 감사합니다! :D

0

워닝은 해결하실 필요 없는 경고메시지입니다. 그냥 놔두시면 됩니다. 거슬린다면 워닝이 뜨지 않는 패키지로 교체하는 수밖에 없습니다.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.04.27

안녕하세요, 인프런 AI 인턴입니다. 챠챠_님의 antd 관련 문제에 대해 도움을 드리고자 합니다.

챠챠_님의 경우 antd 라이브러리 사용 시 Cannot use import statement outside a module 오류에 직면하셨고, next.config.js에 특정 설정을 추가함으로써 문제를 해결하셨다고 합니다. 이어서 등장한 findDOMNode is deprecated 경고 메시지는 React 라이브러리 내부에서 일부 사용되던 메소드가 미래의 주요 버전 업데이트에서 제거될 예정임을 알리는 것입니다.

이와 비슷한 상황에서 유용한 정보를 담은 기존 답변을 찾았습니다. 이 답변은 next.js에서 antd 또는 관련 의존성을 사용할 때 발생하는 문제와 해결 방안에 대해 설명하고 있습니다.

next 13,14버전으로 하고 있는데 antd에서 다음과 같은 오류가 발생합니다.에서 찾은 관련 내용은 다음과 같습니다:

이 답변에서는 SyntaxError: Cannot use import statement outside a module 오류에 대해 질문자가 next.config.js 파일에 transpilePackages 설정을 추가함으로써 문제를 해결했다는 점을 공유했습니다. 이 설정은 next.js 프로젝트에서 antd 등의 패키지를 잘 처리할 수 있도록 도와줍니다.

다만, 챠챠_님의 추가적인 문제인 findDOMNode is deprecated와 관련해 직접적으로 해결 방법을 제시하는 내용은 찾을 수 없었습니다. 이 경고는 주로 라이브러리 내부 구현이나 사용 방법에서 오는 것이므로, 개별 컴포넌트 단위에서 ref를 사용하는 방향으로 점진적으로 코드를 수정해야 할 필요가 있습니다. antd의 경우 해당 라이브러리 업데이트를 통해 해결될 수 있는 문제일 수 있으므로, antd의 공식 문서 또는 깃헙 이슈 페이지에서 관련 정보를 찾아보는 것이 도움이 될 것입니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.