해결된 질문
작성
·
1.4K
·
수정됨
0
강의를 듣던 도중 npm run db:create를 실행시켰는데 아래 에러 메세지가 나옵니다.
> a-nest@0.0.1 db:create
> ts-node ./node_modules/typeorm-extension/dist/cli/index.js db:create -d ./dataSource.ts
node:internal/modules/cjs/loader:942
throw err;
^
Error: Cannot find module './index.js'
Require stack:
- C:\nestStudy\slack-clone-app\a-nest\node_modules\typeorm-extension\dist\cli\imaginaryUncacheableRequireResolveScript
at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
at Function.resolve (node:internal/modules/cjs/helpers:108:19) at requireResolveNonCached (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:549:16)
at getProjectSearchDir (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:519:40)
at phase3 (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:267:27)
at bootstrap (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:47:30)
at main (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:33:12)
at Object.<anonymous> (C:\nestStudy\slack-clone-app\a-nest\node_modules\ts-node\dist\bin.js:579:5)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\nestStudy\\slack-clone-app\\a-nest\\node_modules\\typeorm-extension\\dist\\cli\\imaginaryUncacheableRequireResolveScript'
]
}
Node.js v18.0.0
package.json
{
"name": "a-nest",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev-backup": "nest start --watch",
"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"db:create": "ts-node ./node_modules/typeorm-extension/dist/cli/index.js db:create -d ./dataSource.ts",
"db:drop": "ts-node ./node_modules/typeorm-extension/dist/cli/index.js db:drop -d ./dataSource.ts",
"seed": "ts-node ./node_modules/typeorm-extension/dist/cli/index.js seed -d ./dataSource.ts",
"schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop",
"schema:sync": "ts-node ./node_modules/typeorm/cli.js schema:sync",
"db:migrate": "npm run typeorm migration:run -- -d ./dataSource.ts",
"db:migrate:revert": "npm run typeorm migration:revert -- -d ./dataSource.ts",
"db:create-migration": "npm run typeorm migration:create -- ./src/migrations/",
"db:generate-migration": "npm run typeorm migration:generate -- ./src/migrations -d ./dataSource.ts"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.2",
"@nestjs/typeorm": "^10.0.0",
"mysql2": "^3.6.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"swagger-ui-express": "^5.0.0",
"typeorm-extension": "^3.0.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"run-script-webpack-plugin": "^0.2.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typeorm-model-generator": "^0.4.6",
"typescript": "^5.1.3",
"webpack": "^5.88.2",
"webpack-node-externals": "^3.0.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
index.js 를 못 찾는다는 에러같은데 어디 부분이 잘 못된건지 모르겠습니다ㅠ
이 에러 때문에 테이블들도 생성되지 않았습니다.
답변 2
0
index.js 파일을 못 찾는 것 같은데 어디에 있어야 하는건가요 ?? 답변 주신 dataSource.ts 파일에는 index.js 코드가 작성되어 있지 않았습니다!
0
아래 dataSource.ts 파일을 말씀하신 것이 맞을까요??
import { DataSource } from 'typeorm';
import dotenv from 'dotenv';
import { ChannelChats } from './src/entities/ChannelChats';
import { ChannelMembers } from './src/entities/ChannelMembers';
import { Channels } from './src/entities/Channels';
import { DMs } from './src/entities/DMs';
import { Mentions } from './src/entities/Mentions';
import { Users } from './src/entities/Users';
import { WorkspaceMembers } from './src/entities/WorkspaceMembers';
import { Workspaces } from './src/entities/Workspaces';
dotenv.config();
const dataSource = new DataSource({
type: 'mysql',
host: 'localhost',
port: 3306,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: [
ChannelChats,
ChannelMembers,
Channels,
DMs,
Mentions,
Users,
WorkspaceMembers,
Workspaces,
],
migrations: [__dirname + '/src/migrations/*.ts'],
charset: 'utf8mb4_general_ci',
synchronize: false,
logging: true,
});
export default dataSource;