【问题标题】:SyntaxError: Unexpected reserved word => prettier/third-party.jsSyntaxError: Unexpected reserved word => prettier/third-party.js
【发布时间】:2020-12-17 12:09:07
【问题描述】:

我对 Node、npm 和 webpack 还是很陌生。我正在尝试使用 Tailwind css 设置 Craft 3 environment

开箱即用一切正常,但是当我运行npm run dev 时出现以下错误:

> craftcms-tailwind@1.0.0 dev /Users//sites/***/www
> gulp dev

/Users/***/sites/***/www/node_modules/prettier/third-party.js:9871
      for await (const place of this.config.searchPlaces) {
          ^^^^^

SyntaxError: Unexpected reserved word
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/***/sites/***/www/node_modules/prettier/index.js:16551:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! craftcms-tailwind@1.0.0 dev: `gulp dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the craftcms-tailwind@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/***/.npm/_logs/2020-08-28T14_23_16_034Z-debug.log

为什么会出现这种情况,我如何确保我可以在未来解决这个问题?

【问题讨论】:

  • 你写过代码吗?
  • 我更新/添加/删除了一些 Craft 插件。但是还没有写或接触过任何类型的css/js。
  • 您是否将 Craft 3 包导入到您的代码中?
  • 你的节点版本是什么?
  • @KiJéy 我在 v8.11.3 上运行节点

标签: node.js npm webpack gulp prettier


【解决方案1】:

如此处所述:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of

这个语法:

for await (const place of this.config.searchPlaces) {
  // ...
}

在 NodeJS 10.0.0 开始版本中可用

【讨论】:

    【解决方案2】:
    1. 我首先遇到了同样的问题,我尝试升级 node v8 --> node v10 工作正常。

    2. 如果您不想升级节点版本,您可以将 prettier 版本降级到 prettier@1.13.7 此修复也可以正常工作。

    降级更漂亮的版本:

    npm i -D prettier@1.13.7
    

    更多信息:https://devsnooper.com/syntaxerror-unexpected-reserved-word/

    【讨论】:

      【解决方案3】:

      我在节点 v8.11.2 中遇到了同样的问题。升级节点到 12.3.1 版本,运行正常

      【讨论】:

        【解决方案4】:

        我知道已经很晚了,但是对于来这里的人,您可以使用 node v10 或将 prettier 降级到 v1.x.x。

        如果任何包抛出类似这样的意外错误,请在 github 或 node_module 上检查它的 package.json 并查找 engines

        "engines": {
            "node": ">=8"
        }, 
        

        确保它与您的节点匹配,尽可能更改(升级)节点版本或使用不同(旧)包版本。您可以通过更改此文件的下拉列表中的版本来检查哪个软件包版本适合。

        【讨论】:

          猜你喜欢
          • 2023-02-25
          • 2016-09-28
          • 1970-01-01
          • 2020-03-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-06-24
          • 2019-10-06
          相关资源
          最近更新 更多