티스토리 뷰
[next.js] typeorm 사용시 Critical dependency: the request of a dependency is an expression / module not found: Can't resolve 'X' in with new Next.js project 에러
실전압축코딩 2023. 7. 19. 13:24
next.js에서 서버 컴포넌트에서 typeorm을 사용한 db접속을 구현 하고 있었다.
db 접속, query 실행등은 정상적으로 작동했으나. 엄청난 수의 "Critical dependency: the request of a dependency is an expression" 에러 메시지가 발생했다... 보아하니 typeorm 패키지의 종속성 문제인듯 하였다.
애꿎은 package.json만 여러번 만지던중 typeorm github에서 이미 해당 issue가 report된 것을 확인하였다!
https://github.com/typeorm/typeorm/issues/10047
Plenty of `Module not found: Can't resolve 'X' in` with new Next.js project · Issue #10047 · typeorm/typeorm
Issue description I've created a new brand Next.js project and I'm getting loads of warnings of modules that can't be found Expected Behavior Should be able to load and use typeorm without warnings...
github.com
해결 법은 간단하다.
next.config.js에
const path = require("path");
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["typeorm"],
},
};
module.exports = nextConfig;
를 넣어주면 된다.
서버 컴포넌트의 외부 패키지를 강제로 잡아 주는 것 같다.
을 해주는 녀석이란다.
https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages
next.config.js Options: serverComponentsExternalPackages | Next.js
Using App Router Features available in /app
nextjs.org
serverComponentsExternalPackages는 Server Components bundling시, 혹은 node.js에서 require 함수를 사용시 opt-out specific dependencies를 설정해 주는 거라고 한다. 이 의미는 서버 구성요소로 사용할 외부 패키지를 typeorm으로 지정 해준다는 의미 이다.
'프론트엔드 > React.js' 카테고리의 다른 글
[React.js 3D 에니메이션 만들기(1)] generator(제네레이터) 를 활용해 에니메이션 시퀸스 만들기! with react three fiber/ framer-motion / react three rapier (0) | 2024.11.19 |
---|---|
Rollup + React.js + Typescript 으로 NPM package 배포 하기 (0) | 2024.10.23 |
[NPM에 배포한 React Package 개선] (0) | 2024.07.03 |
React 컴포넌트 Npm에 배포하기 (with TS) (0) | 2023.10.30 |
javascript 물음표 문법 (? , ??) (0) | 2022.07.22 |
- Total
- Today
- Yesterday
- react lane
- 크롬 확장 프로그램 번들링
- vue react
- react setstate
- react render props
- react 배치
- 크롬 확장 프로그램 개발
- render props
- renderlane
- react ref reative
- react batch
- 크롬 확장 프로그램 개발 환경
- 크롬 확장 프로그램 hmr
- eslint
- Vue.js
- typescript
- vue
- vitre
- crxjs/vite-plugin
- table render props
- type annotation type infer
- crxjs/vite-plugin typeerror: crypto.hash is not a function
- react vue
- 리액트 배치
- vue ref
- vue reactive
- 크롬 확장 프로그램 vite
- vue3
- 크롬 확장 프로그램 핫 리로딩
- 타입 어노테이션과 타입 추론
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |