【问题标题】:Running nest.js from VS Code从 VS Code 运行 nest.js
【发布时间】:2017-10-20 01:42:43
【问题描述】:

所以,我正在使用这个新框架 http://nestjs.com/,它看起来非常棒,因为它允许在 Node 上使用 Typescript,很可能是有角度的。

使用启动器https://github.com/kamilmysliwiec/nest-typescript-starter,我可以使用npm run start 毫无问题地运行它,但是由于项目中有一个.vscode,我假设我可以使用VS Code 来运行并获得一些调试能力。

问题是,当我直接从 VS Code 运行时,不更改代码中的任何内容,我会遇到以下问题:

Error: Cannot find module 'nest.js'

我尝试从 VS Code 运行,无论是否从 NPM 运行,都没有成功。

提前致谢。

【问题讨论】:

  • 显然将 launch.json 更改为 "program": "${workspaceRoot}\\index.js" 而不是 "program": "${workspaceRoot}\\src\\server.ts" 并删除 outFiles 完成了这项工作。我把它留在这里看看是否正确。

标签: node.js typescript nestjs


【解决方案1】:

我今天更新了nest-typescript-starter。以前的版本有一个旧的dist 目录,其中包含过时的导入包。如果要编译应用程序,请使用npm run start:prod 脚本。

【讨论】:

    【解决方案2】:

    使用nestjs 应用程序进行调试。 2020年,在我关注first-step之后。 在 VS 代码中更改默认设置:

    "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Program",
          "skipFiles": [
            "<node_internals>/**"
          ],
          "program": "${workspaceFolder}/start",
          "preLaunchTask": "tsc: build - tsconfig.json",
          "outFiles": [
            "${workspaceFolder}/dist/**/*.js"
          ]
        }
      ]
    

    到这里:

    "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Program",
          "skipFiles": ["<node_internals>/**"],
          "program": "${workspaceFolder}/src/main.ts",
          "preLaunchTask": "tsc: build - tsconfig.json",
          "outFiles": ["${workspaceFolder}/dist/**/*.js"]
        }
      ]
    

    然后按 F5 进行调试。 它非常适合我。

    【讨论】:

      【解决方案3】:

      对于那些正在寻找launch.json 的人。在https://github.com/nestjs/nest/issues/776有一个描述

      {
          // Use IntelliSense to learn about possible attributes.
          // Hover to view descriptions of existing attributes.
          // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
          "version": "0.2.0",
          "configurations": [
              {
                  "type": "node",
                  "request": "launch",
                  "name": "Launch Program",
                  "program": "${workspaceFolder}\\src\\main.ts",
                  "preLaunchTask": "tsc: build - tsconfig.json",
                  "outFiles": [
                      "${workspaceFolder}/dist/**/*.js"
                  ]
              }
          ]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-10
        • 2016-08-14
        • 2021-05-10
        • 1970-01-01
        相关资源
        最近更新 更多