Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/#80] MSW 적용 #83

Merged
merged 11 commits into from Oct 16, 2022
29 changes: 29 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
Comment on lines +5 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 vscode 설정파일은 어떤 역할인거야?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요건 breakpoint 걸어두고 디버거 돌리면서 디버깅했는데, nextJS에서 디버깅 돌릴 때 넣어줘야되는 것 같더라고?

},
{
"name": "Next.js: debug client-side",
"type": "pwa-chrome",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev",
"console": "integratedTerminal",
"serverReadyAction": {
"pattern": "started server on .+, url: (https?://.+)",
"uriFormat": "%s",
"action": "debugWithChrome"
}
}
]
}
3 changes: 3 additions & 0 deletions next.config.js
Expand Up @@ -14,6 +14,9 @@ const nextConfig = {
// Docker를 위한 설정
// https://nextjs.org/docs/advanced-features/output-file-tracing
output: 'standalone',
experimental: {
esmExternals: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 어떤 이유로 false로 설정해준거야?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msw가 node 12 기준으로 되어있어서 esm을 지원안하고있어. nextJS 12버전부터는 esmExternals: true가 default인데 true면 CommonJS보다 ESM을 먼저 로딩하는 것 같던데(링크) 그때 충돌이 나는지 MSW사용할 때 에러가 발생하더라고. 그래서 꺼줬어

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pure ESM모듈이 혹시 적용안되나 chalk v5 다운받아서 테스트해봤는데 잘되길래 괜찮구나 싶어서 저렇게 해놨어! 혹시 라이브러리 다운받을 때 이슈생기면 저 부분일 수도 있어서 알아두면 좋을 것 같아

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 오키오키 👍
나도 찾아봤는데 msw이 esm 지원 작업중인 것 같아 링크
나중에 저 PR 반영되면 요 옵션 빼줘도 될 듯!

},
};

module.exports = nextConfig;
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "NODE_OPTIONS=' --no-experimental-fetch' next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down Expand Up @@ -34,6 +34,10 @@
"babel-plugin-styled-components": "^2.0.6",
"eslint": "8.12.0",
"eslint-config-next": "12.1.1",
"msw": "^0.47.4",
"typescript": "4.6.3"
},
"msw": {
"workerDirectory": "public"
}
}
6 changes: 5 additions & 1 deletion pages/_app.tsx
Expand Up @@ -16,6 +16,10 @@ import { userSessionState } from 'src/stores/user';
import axios from 'axios';
import { ROUTE } from 'src/route';

import { setUpMocks } from '../src/api/mock/index';

setUpMocks();

initAxiosConfig();

interface Props extends AppProps {
Expand Down Expand Up @@ -61,7 +65,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
const { ctx } = appContext;

const cookie = ctx.req ? ctx.req.headers.cookie : null;
console.log('success');

let user;
if (cookie) {
axios.defaults.headers.common['cookie'] = cookie;
Expand Down
18 changes: 0 additions & 18 deletions pages/imgviewer.tsx

This file was deleted.