简体   繁体   English

使用 yarn 在 Visual Studio Code 中运行 NodeJS 项目

[英]Running NodeJS project in Visual Studio Code with yarn

I have a NodeJS project which I can start from command line with yarn start command.我有一个 NodeJS 项目,我可以使用yarn start命令从命令行开始。 My package.json looks similar to this:我的package.json看起来与此类似:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2",
    "react": "^15.4.2",
    "redux": "^3.6.0",
  },
  "devDependencies": {
    "babel-cli": "^6.22.2",
    "cross-env": "^3.1.4",
    "eslint": "^3.13.0",
    "pm2": "^2.3.0",
    "redux-mock-store": "^1.2.2",
    "rimraf": "^2.5.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.2.1"
  }
}

I am trying to start this project in debugging mode with Visual Studio Code but with almost no luck.我正在尝试使用 Visual Studio Code 以调试模式启动该项目,但几乎没有运气。 I have defined my launch configuration in VS Code launch.json file like this:我在 VS Code launch.json文件中定义了我的启动配置,如下所示:

{
  // Use IntelliSense to learn about possible Node.js debug 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": "yarn",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        "start"
      ],
      "port": 5858,
      "cwd": "${workspaceRoot}",
      "timeout": 10000
    }
  ]
}

The problem with this configuration is that it usually times-out because webpack-dev-server build is longer than 10 seconds.这个配置的问题是它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 I can increase the timeout in my configuration, but I have noticed that VS Code results with a message Cannot connect to runtime process (timeout after 30000 ms).我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示消息Cannot connect to runtime process (timeout after 30000 ms). eventually, so I assume that this is not a good solution.最终,所以我认为这不是一个好的解决方案。 Also, my breakpoints are ignored with this kind of config which tells me that I am definitely doing something wrong here.此外,这种配置会忽略我的断点,这告诉我我肯定在这里做错了。

This is the first time I am trying out Visual Studio Code and I usually don't use NodeJS, but I got this project with all these scripts in package.json already defined so I'm trying to adopt to it and therefore all the confusion about how to run it properly.这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我得到了这个项目,其中包含package.json中的所有这些脚本,所以我正在尝试采用它,因此所有的混乱关于如何正确运行它。

Can Visual Studio Code run a project like this with full debugging functionality at all, and if so, how should I configure my launch script? Visual Studio Code 可以运行这样一个具有完整调试功能的项目吗?如果可以,我应该如何配置我的启动脚本?

I have a NodeJS project which I can start from command line with yarn start command.我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start My package.json looks similar to this:我的package.json看起来类似于:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2",
    "react": "^15.4.2",
    "redux": "^3.6.0",
  },
  "devDependencies": {
    "babel-cli": "^6.22.2",
    "cross-env": "^3.1.4",
    "eslint": "^3.13.0",
    "pm2": "^2.3.0",
    "redux-mock-store": "^1.2.2",
    "rimraf": "^2.5.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.2.1"
  }
}

I am trying to start this project in debugging mode with Visual Studio Code but with almost no luck.我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 I have defined my launch configuration in VS Code launch.json file like this:我在 VS Code launch.json文件中定义了我的启动配置,如下所示:

{
  // Use IntelliSense to learn about possible Node.js debug 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": "yarn",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        "start"
      ],
      "port": 5858,
      "cwd": "${workspaceRoot}",
      "timeout": 10000
    }
  ]
}

The problem with this configuration is that it usually times-out because webpack-dev-server build is longer than 10 seconds.这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 I can increase the timeout in my configuration, but I have noticed that VS Code results with a message Cannot connect to runtime process (timeout after 30000 ms).我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). eventually, so I assume that this is not a good solution.最终,所以我认为这不是一个好的解决方案。 Also, my breakpoints are ignored with this kind of config which tells me that I am definitely doing something wrong here.此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

This is the first time I am trying out Visual Studio Code and I usually don't use NodeJS, but I got this project with all these scripts in package.json already defined so I'm trying to adopt to it and therefore all the confusion about how to run it properly.这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Can Visual Studio Code run a project like this with full debugging functionality at all, and if so, how should I configure my launch script? Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

I have a NodeJS project which I can start from command line with yarn start command.我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start My package.json looks similar to this:我的package.json看起来类似于:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2",
    "react": "^15.4.2",
    "redux": "^3.6.0",
  },
  "devDependencies": {
    "babel-cli": "^6.22.2",
    "cross-env": "^3.1.4",
    "eslint": "^3.13.0",
    "pm2": "^2.3.0",
    "redux-mock-store": "^1.2.2",
    "rimraf": "^2.5.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.2.1"
  }
}

I am trying to start this project in debugging mode with Visual Studio Code but with almost no luck.我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 I have defined my launch configuration in VS Code launch.json file like this:我在 VS Code launch.json文件中定义了我的启动配置,如下所示:

{
  // Use IntelliSense to learn about possible Node.js debug 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": "yarn",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        "start"
      ],
      "port": 5858,
      "cwd": "${workspaceRoot}",
      "timeout": 10000
    }
  ]
}

The problem with this configuration is that it usually times-out because webpack-dev-server build is longer than 10 seconds.这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 I can increase the timeout in my configuration, but I have noticed that VS Code results with a message Cannot connect to runtime process (timeout after 30000 ms).我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). eventually, so I assume that this is not a good solution.最终,所以我认为这不是一个好的解决方案。 Also, my breakpoints are ignored with this kind of config which tells me that I am definitely doing something wrong here.此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

This is the first time I am trying out Visual Studio Code and I usually don't use NodeJS, but I got this project with all these scripts in package.json already defined so I'm trying to adopt to it and therefore all the confusion about how to run it properly.这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Can Visual Studio Code run a project like this with full debugging functionality at all, and if so, how should I configure my launch script? Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

I have a NodeJS project which I can start from command line with yarn start command.我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start My package.json looks similar to this:我的package.json看起来类似于:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2",
    "react": "^15.4.2",
    "redux": "^3.6.0",
  },
  "devDependencies": {
    "babel-cli": "^6.22.2",
    "cross-env": "^3.1.4",
    "eslint": "^3.13.0",
    "pm2": "^2.3.0",
    "redux-mock-store": "^1.2.2",
    "rimraf": "^2.5.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.2.1"
  }
}

I am trying to start this project in debugging mode with Visual Studio Code but with almost no luck.我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 I have defined my launch configuration in VS Code launch.json file like this:我在 VS Code launch.json文件中定义了我的启动配置,如下所示:

{
  // Use IntelliSense to learn about possible Node.js debug 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": "yarn",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        "start"
      ],
      "port": 5858,
      "cwd": "${workspaceRoot}",
      "timeout": 10000
    }
  ]
}

The problem with this configuration is that it usually times-out because webpack-dev-server build is longer than 10 seconds.这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 I can increase the timeout in my configuration, but I have noticed that VS Code results with a message Cannot connect to runtime process (timeout after 30000 ms).我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). eventually, so I assume that this is not a good solution.最终,所以我认为这不是一个好的解决方案。 Also, my breakpoints are ignored with this kind of config which tells me that I am definitely doing something wrong here.此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

This is the first time I am trying out Visual Studio Code and I usually don't use NodeJS, but I got this project with all these scripts in package.json already defined so I'm trying to adopt to it and therefore all the confusion about how to run it properly.这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Can Visual Studio Code run a project like this with full debugging functionality at all, and if so, how should I configure my launch script? Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

I have a NodeJS project which I can start from command line with yarn start command.我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start My package.json looks similar to this:我的package.json看起来类似于:

{
  "name": "projectname",
  "version": "0.0.1",
  "description": "",
  "author": "My Name",
  "license": "",
  "scripts": {
    "start": "yarn dev",
    "dev": "yarn stop && pm2 start pm2-dev.yaml && webpack-dev-server --progress",
    "prod": "yarn stop && yarn build && pm2 start pm2-prod.yaml",
    "build": "rimraf dist lib && babel src -d lib --ignore test.js && cross-env NODE_ENV=production webpack -p --progress",
    "stop": "rimraf logs/* && pm2 delete all || true"
  },
  "dependencies": {
    "body-parser": "~1.16.0",
    "ejs": "2.5.5",
    "express": "^4.14.1",
    "pg": "^6.1.2",
    "react": "^15.4.2",
    "redux": "^3.6.0",
  },
  "devDependencies": {
    "babel-cli": "^6.22.2",
    "cross-env": "^3.1.4",
    "eslint": "^3.13.0",
    "pm2": "^2.3.0",
    "redux-mock-store": "^1.2.2",
    "rimraf": "^2.5.4",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.2.1"
  }
}

I am trying to start this project in debugging mode with Visual Studio Code but with almost no luck.我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 I have defined my launch configuration in VS Code launch.json file like this:我在 VS Code launch.json文件中定义了我的启动配置,如下所示:

{
  // Use IntelliSense to learn about possible Node.js debug 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": "yarn",
      "runtimeExecutable": "yarn",
      "runtimeArgs": [
        "start"
      ],
      "port": 5858,
      "cwd": "${workspaceRoot}",
      "timeout": 10000
    }
  ]
}

The problem with this configuration is that it usually times-out because webpack-dev-server build is longer than 10 seconds.这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 I can increase the timeout in my configuration, but I have noticed that VS Code results with a message Cannot connect to runtime process (timeout after 30000 ms).我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). eventually, so I assume that this is not a good solution.最终,所以我认为这不是一个好的解决方案。 Also, my breakpoints are ignored with this kind of config which tells me that I am definitely doing something wrong here.此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

This is the first time I am trying out Visual Studio Code and I usually don't use NodeJS, but I got this project with all these scripts in package.json already defined so I'm trying to adopt to it and therefore all the confusion about how to run it properly.这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Can Visual Studio Code run a project like this with full debugging functionality at all, and if so, how should I configure my launch script? Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

Thanks for the information shared in this thread, What exactly is the 'react-scripts start' command?感谢您在此线程中共享的信息, “react-scripts start”命令到底是什么? , by @johndpope. ,由@johndpope 提供。

Here is the setup I used in vscode's launch.json file in configurations section for launching a react process.这是我在 vscode 的launch.json文件中使用的设置,位于configurations部分,用于启动反应过程。

{
        "name": "Launch: Frontend Server",
        "program": "${workspaceFolder}/node_modules/react-scripts/bin/react-scripts.js",
        "args": ["start"],
        "request": "launch",
        "type": "node",
        "console": "integratedTerminal",
        "localRoot": "${workspaceFolder}",
}

So, response to the original post, you may try to see what is the script used in rimraf library.因此,回复原始帖子,您可以尝试查看rimraf库中使用的脚本是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM