0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

autoprefixerやpostCSS の実行時のエラー「ERROR: "postcss" exited with 1.」を回避する方法。

Posted at

事象

現在のnodeの最新LTSバージョンは16系ですが、業務で少し古いnode12系のプロジェクトへautoprefixerを導入することがありました。
autoporefixerのタスクを作成し、実行したところ以下のようなエラーが発生しました。

/Users/xxxx/s/npm-sass/node_modules/yaml/dist/compose/composer.js:33
                if (prelude[i + 1]?.[0] !== '#')

/Users/xxxx/s/npm-sass/node_modules/yaml/dist/compose/composer.js:33

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/xxxx/s/npm-sass/node_modules/yaml/dist/index.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
ERROR: "postcss" exited with 1.

解決方法

使用しているpostcss-cliのバージョンを10未満に変更します。
npmの該当ページでバージョンを確認すると10未満の最新は、9.1.0なので以下のように変更します。package.jsonを以下のように変更します。

package.json
  ...
  "dependencies": {
-   "postcss-cli": "^10.0.0",
+   "postcss-cli": "9.1.0",
  },

その後、再インストールするの問題のエラーはなく動作することができました。

# 適宜、モジュールを削除してから再インストール。
rm -rf node_modules package-lock.json
npm i
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?