SunShare
V2EX  ›  Node.js

用 ES6 语法(包含 import 和 export)写的 nodejs 服务端脚步,如何在 webstorm 里调试?

  •  
  •   SunShare · Jul 20, 2016 · 10465 views
    This topic created in 3605 days ago, the information mentioned may be changed or developed.
    因为 nodejs 目前还不能完全支持 ES6 ,只能进一步转换,比如 babel 转换( babel - node 代替 node 命令)。

    但一时不知道怎么在 webstorm 里配置并调试代码。
    9 replies    2016-07-21 21:35:01 +08:00
    ljcarsenal
        1
    ljcarsenal  
       Jul 20, 2016 via Android
    Sourcemap 支持不…
    AlloVince
        2
    AlloVince  
       Jul 20, 2016
    Debug 时 Node interpreter 直接配置为 babel-node 就行了
    SunShare
        3
    SunShare  
    OP
       Jul 20, 2016
    @AlloVince

    babel-node 命令是被局部安装到 node_modules/.bin ,所以通过 package 里的 scripts 的声明执行,比如:

    "scripts": {
    "build": "babel-node index.js"
    }

    webstorm 配置 Run / debug 时,添加 jnpm 的配置项,添加 Node interpreter 为: node_modules/.bin/babel-node 。


    然后,无法启动。难道 babel - node 要全局命令

    nodejs 接触不久, 请多多指教!
    johnhsm2333
        4
    johnhsm2333  
       Jul 20, 2016
    @imjeen

    "scripts": {
    "build": "./node_modules/.bin/babel-node index.js"
    }

    局部安装的话,应该这样使用。
    wakiki
        5
    wakiki  
       Jul 20, 2016 via Android
    nodejs6 好像已经支持 es6
    SunShare
        6
    SunShare  
    OP
       Jul 20, 2016
    @johnhsm2333 可以调试了,但是

    import a from '/path/to/a'; 然后在后面断点上,此变量名为 undefined 。

    好像 import 时都会被转化成其他名字,还是没法调试源码。
    FrankFang128
        7
    FrankFang128  
       Jul 20, 2016 via Android
    去掉 转义,啥事没有
    Sirormy
        8
    Sirormy  
       Jul 21, 2016
    我的 nodejs 是 5.5 可以使用 ES6 啊, 反正我用到的新特性都没问题
    SunShare
        9
    SunShare  
    OP
       Jul 21, 2016
    @Sirormy

    nodejs 只是部分支持 ES6 ,因为是基于 V8 引擎的 (ECMAScript 2015 (ES6) and beyond)[https://nodejs.org/en/docs/es6/]。

    很显然 nodejs 目前还不支持比如 import 和 export 等语法。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1184 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 93c8b4a0 · 657ms · UTC 17:41 · PVG 01:41 · LAX 10:41 · JFK 13:41
    ♥ Do have faith in what you're doing.