인프런 커뮤니티 질문&답변
yarn run server 에러 발생
해결된 질문
작성
·
718
0
nodemon ./src/index.js
위 커맨드 실행시 에러가 발생합니다. yarn 2 버전을 사용하고 있는데 버전 1로 다운그레이드 해도 동일한 현상이 발생하네요.. 의존성 관리에 문제가 있는 것 같은데 해결책이 있을까요? 폴더 구조는 강의와 동일합니다.
// package.json
{
  "version": "1.0.0",
  "name": "node-graphql",
  "private": true,
  "workspaces": [
    "client",
    "server"
  ],
  "scripts": {
    "frontend": "yarn workspace client start",
    "server": "yarn workspace server start"
  }
}
// server/package.json
{
  "version": "1.0.0",
  "name": "server",
  "main": "index.js",
  "type": "module",
  "license": "MIT",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.15"
  },
  "scripts": {
    "start": "nodemon ./src/index.js"
  }
}
에러 내용
(node:76305) ExperimentalWarning: The ESM module loader is experimental. internal/modules/run_main.js:54 internalBinding('errors').triggerUncaughtException( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'express' imported from /Users/iyuun/WebstormProjects/node-graphql/server/src/index.js Did you mean to import express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/index.js?
server 폴더에서 express 깔았는데도 그러네요..
답변 2
2

yarn pnp 사용했을 때 나타나는 에러인 것 같습니다. pnp module 시스템에서 esm을 지원하지 않아서 package.json에 "type": "module"을 추가해도 원하는 패키지를 찾을 수가 없네요.
관련 이슈: https://github.com/yarnpkg/berry/issues/638
.yarnrc.yml 파일에
nodeLinker: node-modules
이렇게 설정해줘서 해결하긴 했는데 강의에는 관련 내용이 없는 걸 보니 pnp 사용을 안해서 그런 건지 궁금하네요.
0

server/src/index.js 입니다!
import express from 'express';
import cors from 'cors';
import messagesRoute from './routes/messages.js'
import usersRoute from './routes/users.js'
const app = express();
app.use(express.urlencoded({ extended: true }))
app.use(express.json());
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}))
const routes = [...messagesRoute, ...usersRoute];
routes.forEach(({ method, route, handler}) => {
app[method](route, handler)
})
app.listen(8000, () => {
console.log('server listening on 8000..')
})







네, yarn 1.0 베이스에요. yarn berry 사용시에는 그런 문제가 있군요..
시시각각 변하는 라이브러리가 많아 일일이 대응하기가 힘든 측면이 있습니다.
양해 부탁드리고, 답변주신 내용은 강의노트에 추가해 놓겠습니다. 감사합니다!