SyntaxError: Unexpected reserved word => prettier/third-party.js

SyntaxError: Unexpected reserved word => prettier/third-party.js

我对 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

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

如此处所述: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 开始可用

我在节点 v8.11.2 中遇到了同样的问题。已将节点升级到版本 12.3.1,并且工作正常

  1. 我第一次遇到同样的问题我尝试升级 node v8 --> node v10 工作正常。

  2. 如果你不想升级你的节点版本,你可以将更漂亮的版本降级到prettier@1.13.7 此修复程序也正常工作。

降级更漂亮的版本:

npm i -D prettier@1.13.7

更多信息:https://dev.to/shivampawar/syntaxerror-unexpected-reserved-word-prettierthird-partyjs-3ph7

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

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

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

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