【问题标题】:Debug Node/Express Application in intellij ultimate 2017.1在 intellij Ultimate 2017.1 中调试 Node/Express 应用程序
【发布时间】:2017-12-13 14:57:51
【问题描述】:

我正在尝试调试我的 express 应用程序,我已根据 intellij 帮助文档配置了我的 IDE。但是当我运行应用程序时,该过程永远不会在断点处停止。

请在下面找到我的配置窗口详细信息:

Intellij 版本:2017.1 波纹管是我在调试器控制台中看到的:

/Users/xxxxx/.nvm/versions/node/v8.1.2/bin/node --inspect-
brk=64692 /Users/xxxxx/Documents/WORKSPACE/acme-
web/services/acme.js
Debugger listening on ws://127.0.0.1:64692/453107ba-002c-4066-9b4c-
531e111aec87
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...

我的应用程序在 8080 端口上运行。

我是否遗漏了什么,任何指针都会有所帮助

编辑:

我曾尝试使用 IJ-EAP-2017.2。这在尝试调试时在控制台中给了我一个新错误。

/Users/user-xxxx/.nvm/versions/node/v8.1.2/bin/node --inspect-brk=55169 /Users/user-xxxx/Documents/WORK/acme-prj-web/src/common/pages/yyyyPage.js
Debugger listening on port 55169.
Debugger attached.
/Users/user-xxxx/Documents/WORK/acme-prj-web/src/common/pages/yyyyPage.js:1
(function (exports, require, module, __filename, __dirname) { import React, { Component, PropTypes } from "react";
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
Waiting for the debugger to disconnect...

Process finished with exit code 1

我不确定为什么我们会收到此错误,但仍在努力使调试器正常工作。

SyntaxError: Unexpected token import
    at createScript (vm.js:53:10)

【问题讨论】:

  • 用node正常运行时是否也会出现该错误?没有看到代码,我们不能说这里出了什么问题。
  • 这不会正常发生。仅在启动调试器时才看到此错误。在项目中,我们使用 Babel、ES6 和 webpack 以及 node/express
  • 您的浏览器控制台或模块加载器中是否有任何错误?您的网络应用是否按预期工作?
  • 是的,我们没有在 Web 控制台中看到任何错误。该应用程序按预期工作。仅当我尝试在 intellij 中进行调试时才看到此错误。目前我正在使用 Ultimate 2017.1,我也尝试使用 2017.2-EAP

标签: node.js reactjs express intellij-idea node-inspector


【解决方案1】:

问题出在:import & export ES6 的语法还没有被 Node.js 支持。不幸的是,当前的best proposal 仍处于draft 状态。

您可以使用的一些解决方案:

  • 解决方案 1:使用Babel 启用对 ES6(和 ES6+)语法的完全支持。只需关注the official installation guideline 即可完成。您还需要使用 babel-node 才能调试 ES6 完整语法。
  • 解决方案 2(推荐):使用 require & module.exports 回到旧的方式(考虑您是否真的需要 import / export)。等到 Node.js 正式发布对 ES6 的全面支持。

希望这可以帮助:)

【讨论】:

  • 另一种解决方案是使用 TypeScript。
【解决方案2】:

请尝试 2​​017.2 EAP:https://www.jetbrains.com/idea/nextversion/。自 2017.1 起,Node 8 的一些问题已得到修复。

【讨论】:

  • 我已经尝试了 EAP,但没有任何运气。使用 EAP 时,调试器会以代码 1 退出。
  • 这是否意味着我需要换一个IDE?
  • 没有。只是不要尝试使用 Node.js 运行客户端代码
【解决方案3】:

从错误消息看来,您正在尝试使用 Node.js 运行 React 组件。 React 应用程序通常由浏览器执行,这是一个客户端代码,因此您必须构建您的应用程序,启动它所在的服务器,然后在浏览器中使用JavaScript Debug 运行配置对其进行调试。

请参阅https://blog.jetbrains.com/webstorm/2017/01/debugging-react-apps/ 了解有关调试 React 应用程序的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多