【问题标题】:SyntaxError: Unexpected token ... in serialport in node_modulesSyntaxError: Unexpected token ... in serialport in node_modules
【发布时间】:2020-05-15 18:12:40
【问题描述】:

我一直在尝试运行 vue-electron 应用程序。但是出现以下错误。

  App threw an error during load
  C:\newFolder02\pos4-desktop\node_modules\@serialport\stream\lib\index.js:103
    const settings = { ...defaultSettings, ...options }
                       ^^^

  SyntaxError: Unexpected token ...
      at createScript (vm.js:74:10)
      at Object.runInThisContext (vm.js:116:10)
      at Module._compile (module.js:533:28)
      at Object.Module._extensions..js (module.js:580:10)
      at Module.load (module.js:503:32)
      at tryModuleLoad (module.js:466:12)
      at Function.Module._load (module.js:458:3)
      at Module.require (module.js:513:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (C:\newFolder02\pos4-desktop\node_modules\serialport\lib\index.js:1:175)

错误来自以下行。

const settings = { ...defaultSettings, ...options }

我使用以下工具

  • 节点 8.16.0
  • npm 6.4.1
  • 电子 1.8.2

它在 Windows 中不起作用。但它适用于 Mac OS。 任何想法..?

【问题讨论】:

  • 您的节点环境不支持应该已经包含在节点 8.16 中的 ES6 语法
  • @fodma1 是的。是真的。该软件的开发始于一年多前。升级到最新版本是最好的解决方案。

标签: node.js vue.js electron node-serialport electron-vue


【解决方案1】:

我找到了解决办法。您可以使用 Babel(https://babeljs.io/en/repl) 将 ES6 代码转换为原始 JavaScript 代码。

我通过 Babel 将 ES6 代码转换为原生 JavaScript。我在左侧边栏中勾选了 ENV PRESET。我将 Electron 设置为“1.8”,将 Node 设置为“8.16”。它运作良好。 Babel Screenshot

【讨论】:

    猜你喜欢
    • 2020-09-04
    • 1970-01-01
    • 2018-01-07
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多