繁体   English   中英

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

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

我有一个 NodeJS 项目,我可以使用yarn start命令从命令行开始。 我的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"
  }
}

我正在尝试使用 Visual Studio Code 以调试模式启动该项目,但几乎没有运气。 我在 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
    }
  ]
}

这个配置的问题是它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示消息Cannot connect to runtime process (timeout after 30000 ms). 最终,所以我认为这不是一个好的解决方案。 此外,这种配置会忽略我的断点,这告诉我我肯定在这里做错了。

这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我得到了这个项目,其中包含package.json中的所有这些脚本,所以我正在尝试采用它,因此所有的混乱关于如何正确运行它。

Visual Studio Code 可以运行这样一个具有完整调试功能的项目吗?如果可以,我应该如何配置我的启动脚本?

我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start 我的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"
  }
}

我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 我在 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
    }
  ]
}

这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). 最终,所以我认为这不是一个好的解决方案。 此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start 我的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"
  }
}

我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 我在 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
    }
  ]
}

这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). 最终,所以我认为这不是一个好的解决方案。 此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start 我的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"
  }
}

我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 我在 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
    }
  ]
}

这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). 最终,所以我认为这不是一个好的解决方案。 此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

我有一个 NodeJS 项目,我可以使用yarn start命令从命令行yarn start 我的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"
  }
}

我正在尝试使用 Visual Studio Code 在调试模式下启动这个项目,但几乎没有运气。 我在 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
    }
  ]
}

这种配置的问题在于它通常会超时,因为webpack-dev-server构建时间超过 10 秒。 我可以在我的配置中增加timeout ,但我注意到 VS Code 结果显示一条消息Cannot connect to runtime process (timeout after 30000 ms). 最终,所以我认为这不是一个好的解决方案。 此外,这种配置会忽略我的断点,这告诉我我在这里肯定做错了。

这是我第一次尝试 Visual Studio Code,我通常不使用 NodeJS,但是我在package.json已经定义了所有这些脚本的这个项目,所以我试图采用它,因此所有的混乱关于如何正确运行它。

Visual Studio Code 能否运行这样一个具有完整调试功能的项目,如果可以,我应该如何配置我的启动脚本?

感谢您在此线程中共享的信息, “react-scripts start”命令到底是什么? ,由@johndpope 提供。

这是我在 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}",
}

因此,回复原始帖子,您可以尝试查看rimraf库中使用的脚本是什么。

暂无
暂无

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

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