【问题标题】:NodeJs, es6 debugging issue in VSCVSC 中的 NodeJs、es6 调试问题
【发布时间】:2019-10-20 14:46:09
【问题描述】:

我正在尝试在 Visual Studio Code 中调试 nodeJS 代码,但不幸的是我得到了以下信息:

(function (exports, require, module, __filename, __dirname) { import { start } from './server'

据我所知,这意味着不支持es6功能,但我认为我的package.json.babelrc是正确的。
.babelrc:

  "presets": [
    "es2015",
    ["@babel/env", {
      "targets": {
        "node": "current"
      }
    }]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-object-rest-spread"
  ],
  "sourceMaps": true,
  "retainLines": true
}

package.json:

  "devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^8.2.1",
    "babel-jest": "^23.4.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-register": "^6.26.0",
    "eslint": "^4.15.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-config-standard": "^11.0.0",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-jest": "^21.15.1",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-prettier": "^2.6.2",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-standard": "^3.1.0",
    "jest": "^23.6.0",
    "mock-req-res": "^1.0.2",
    "mongodb-memory-server": "^5.2.8",
    "nodemon": "^1.18.3",
    "prettier": "^1.15.2",
    "rimraf": "^2.6.2",
    "supertest": "^3.3.0"
  },

任何想法有什么问题吗?

【问题讨论】:

    标签: ecmascript-6 visual-studio-code babeljs


    【解决方案1】:

    我觉得你应该试试

    "presets": [
       [
          "@babel/preset-env",
          {
            "targets": {
              "node": "current"
            }
          }
       ]
    ],
    

    它会根据节点的需要自动编译你的代码

    【讨论】:

    • 不幸的是,这并没有解决我的问题。同样的错误仍然存​​在。
    • 你能分享一下代码要点吗?我将能够运行和调试它。
    猜你喜欢
    • 2018-10-14
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 2017-06-16
    • 2023-02-17
    相关资源
    最近更新 更多