将webpack与hotreload连接后,nestjs呈现错误

时间:2019-05-31 19:37:16

标签: nest

我遵循了nestJs的教程,并有一个基本的工作应用程序。之后,我尝试了本教程将应用程序与webpack和hotreloading连接起来,现在出现以下错误:

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:703:23)

我尝试查看类似的错误,并且除了这里和那里的提示以外,找不到任何结论性内容,这些都是我的测试文件中未编译的内容-任何方向将不胜感激。

使用节点12,npm 6.9.0

将JSON打包如下:

"scripts": {
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "node dist/server",
    "webpack": "webpack --config webpack.config.js",
    "start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rimraf dist && npm run build",
    "start:prod": "node dist/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "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"
  },
  "dependencies": {
    "@nestjs/common": "^6.0.4",
    "@nestjs/core": "^6.0.4",
    "@nestjs/microservices": "^6.0.4",
    "@nestjs/platform-express": "^6.0.4",
    "@nestjs/swagger": "^3.0.2",
    "@nestjs/typeorm": "^6.1.1",
    "@nestjs/websockets": "^6.0.4",
    "mysql": "^2.17.1",
    "reflect-metadata": "0.1.13",
    "rimraf": "2.6.3",
    "rxjs": "6.4.0",
    "swagger-ui-express": "^4.0.4",
    "typeorm": "^0.2.17"
  },
  "devDependencies": {
    "@nestjs/testing": "6.1.1",
    "@types/express": "^4.16.1",
    "@types/jest": "24.0.11",
    "@types/node": "11.13.4",
    "@types/supertest": "2.0.7",
    "concurrently": "^4.1.0",
    "jest": "24.7.1",
    "nodemon": "1.18.11",
    "prettier": "1.17.0",
    "supertest": "4.0.2",
    "ts-jest": "24.0.2",
    "ts-loader": "^6.0.1",
    "ts-node": "8.1.0",
    "tsconfig-paths": "3.8.0",
    "tslint": "5.16.0",
    "typescript": "3.4.3",
    "wait-on": "^3.2.0",
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2",
    "webpack-node-externals": "^1.7.2"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }

2 个答案:

答案 0 :(得分:0)

这可能是tsconfig,您使用的是: "module": "commonjs"compilerOptions中?在使用nodejs时,这是您必须使用的选项

答案 1 :(得分:0)

我最终将此内容发布在NestJS存储库上,并收到了有兴趣的人的答复: https://github.com/nestjs/nest/issues/2389