npm run start 工作正常,但 npm run start: dev 抛出此错误:
\n\n7:14:22 PM - Found 0 errors. Watching for file changes.\ninternal/modules/cjs/loader.js:638\nthrow err;\n^\nError: Cannot find module \'src/models/note.model\'\nat Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)\nat Function.Module._load (internal/modules/cjs/loader.js:562:25)\nat Module.require (internal/modules/cjs/loader.js:692:17)\nat require (internal/modules/cjs/helpers.js:25:18)\nat Object.<anonymous> (C:\\Users\\Anuitex-169\\Desktop\\VersF\\nest\\server\\dist\\note\\note.service.js:17:22)\nat Module._compile (internal/modules/cjs/loader.js:778:30)\nat Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)\nat Module.load (internal/modules/cjs/loader.js:653:32)\nat tryModuleLoad (internal/modules/cjs/loader.js:593:12)\nat Function.Module._load (internal/modules/cjs/loader.js:585:3)\nRun Code Online (Sandbox Code Playgroud)\n\n这个错误从我的项目一开始就出现了,我不明白为什么。我决定忘记这个问题,因为 npm run start 效果很好。但不知怎的有点不舒服(
\n\n我的 app.module.ts \n我的 package.json 文件:
\n\n {\n "name": "server",\n "version": "0.0.1",\n "description": "",\n "author": "",\n "license": "MIT",\n "scripts": {\n "build": "rimraf dist && tsc -p tsconfig.build.json",\n "format": "prettier --write \\"src/**/*.ts\\"",\n "start": "ts-node -r tsconfig-paths/register src/main.ts",\n "start:dev": "tsc-watch -p tsconfig.build.json --onSuccess \\"node dist/main.js\\"",\n "start:debug": "tsc-watch -p tsconfig.build.json --onSuccess \\"node --inspect-brk dist/main.js\\"",\n "start:prod": "node dist/main.js",\n "lint": "tslint -p tsconfig.json -c tslint.json",\n "test": "jest",\n "test:watch": "jest --watch",\n "test:cov": "jest --coverage",\n "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",\n "test:e2e": "jest --config ./test/jest-e2e.json"\n },\n "dependencies": {\n "@nestjs/common": "^6.0.0",\n "@nestjs/core": "^6.0.0",\n "@nestjs/platform-express": "^6.0.0",\n "@nestjs/typeorm": "^6.1.3",\n "mongodb": "^3.3.2",\n "path": "^0.12.7",\n "reflect-metadata": "^0.1.12",\n "rimraf": "^2.6.2",\n "rxjs": "^6.3.3",\n "typeorm": "^0.2.19"\n },\n "devDependencies": {\n "@nestjs/testing": "^6.0.0",\n "@types/express": "4.16.1",\n "@types/jest": "24.0.11",\n "@types/multer": "^1.3.10",\n "@types/node": "11.13.4",\n "@types/supertest": "2.0.7",\n "jest": "24.7.1",\n "prettier": "1.17.0",\n "supertest": "4.0.2",\n "ts-jest": "24.0.2",\n "ts-node": "8.1.0",\n "tsc-watch": "2.2.1",\n "tsconfig-paths": "3.8.0",\n "tslint": "5.16.0",\n "typescript": "3.4.3"\n },\n "jest": {\n "moduleFileExtensions": [\n "js",\n "json",\n "ts"\n ],\n "rootDir": ".",\n "roots": [\n "<rootDir>/src/",\n "<rootDir>/libs/",\n "<rootDir>/apps/"\n ],\n "testRegex": ".spec.ts$",\n "transform": {\n "^.+\\\\.(t|j)s$": "ts-jest"\n },\n "coverageDirectory": "./coverage",\n "testEnvironment": "node"\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n\n请帮我解决这个问题。
\n您的 AppModule 看起来不错,所以我想知道您的 NoteService 中是否发生了某些情况,这一行使得看起来就是这种情况at Object.<anonymous> (C:\Users\Anuitex-169\Desktop\VersF\nest\server\dist\note\note.service.js:17:22)。
src如果我必须打赌,当您位于目录中时,您会尝试从目录中读取模块dist(至少通过标准 Typescript 编译)。您不应使用像这样的导入,而src/models/note.model应该使用考虑当前文件路径的导入(例如../models/note.model)。您可能需要稍微改变一下,但这就是应该发生的事情的想法
| 归档时间: |
|
| 查看次数: |
9143 次 |
| 最近记录: |