2016-03-13 29 views
10

Thông thường để khởi động thông qua dòng lệnh, tôi có thể gõ:Chạy babel-nút trong mã visual studio

babel-node server.js 

Khi tôi cố gắng thiết lập này để breakpoint và những gì không làm việc trong mã visual studio Tôi nhận :

/Users/me/proj/node_modules/babel-cli/lib/babel-node.js --debug-brk=31893 --nolazy server.js 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 4: Dockerfile: command not found 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `(' 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.' 

tôi phỏng đoán nó đã làm với thực tế là thực thi đang được gọi là từ thư mục đó, chứ không phải là từ cùng thư mục với file server.js - nhưng tôi thực sự không biết.

launch.json

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "name": "Launch", 
      "type": "node", 
      "request": "launch", 
      "program": "${workspaceRoot}/server.js", 
      "stopOnEntry": false, 
      "args": [], 
      "cwd": "${workspaceRoot}", 
      "preLaunchTask": null, 
      "runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/lib/babel-node.js", 
      "runtimeArgs": [ 
       "--nolazy" 
      ], 
      "env": { 
       "NODE_ENV": "development" 
      }, 
      "externalConsole": false, 
      "sourceMaps": false, 
      "outDir": null 
     }, 
     { 
      "name": "Attach", 
      "type": "node", 
      "request": "attach", 
      "port": 5858, 
      "address": "localhost", 
      "restart": false, 
      "sourceMaps": false, 
      "outDir": null, 
      "localRoot": "${workspaceRoot}", 
      "remoteRoot": null 
     } 
    ] 
} 

Trả lời

16

Lỗi này xảy ra bởi vì các tập tin babel-node.js không phải là babel-node thực thi nhưng một file wrapper có thêm cờ nút:

babel-Node.js

/* eslint indent: 0 */ 

/** 
* This tiny wrapper file checks for known node flags and appends them 
* when found, before invoking the "real" _babel-node(1) executable. 
*/ 

Để khắc phục điều này, vị trí của số nhị phân babel-node nên được đặt làm giá trị của thuộc tính runtimeExecutable. Với vị trí là:

"${workspaceRoot}/node_modules/.bin/babel-node" 
+4

đáng chú ý rằng tôi cần phải thêm '.cmd' để con đường để có được nó làm việc trong Windows – cgatian

+0

@cgatian bạn có thể xin giải thích như thế nào và nơi mà bạn đã thêm này của nó? – Jag

+0

launch.json tôi tin. – cgatian

Các vấn đề liên quan