質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Babel

Babelは、JavaScriptの次世代仕様であるECMAScriptのコンパイラ。次世代の標準機能を用いて記述されたコードを、それらの機能に対応していないブラウザでも動作するコードに変換することができます。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

解決済

1回答

1633閲覧

babel-plugin-external-helpersが認識されない?

KazuhiroHatano

総合スコア7804

npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Babel

Babelは、JavaScriptの次世代仕様であるECMAScriptのコンパイラ。次世代の標準機能を用いて記述されたコードを、それらの機能に対応していないブラウザでも動作するコードに変換することができます。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

1グッド

0クリップ

投稿2019/10/23 02:32

編集2019/10/23 02:34

前提・実現したいこと

WPのプラグイン開発において
babel-plugin-external-helpersを用いて
jsxコンパイル時の共通コードを1ファイルにまとめようとしています

発生している問題・エラーメッセージ

external-helpersをインストールしたのですが
コンパイル処理において当該のpluginが認識されないです

ReferenceError: Unknown plugin "external-helpers" specified in "/Users/[username]/Documents/htdocs/[project_name]/wp-content/plugins/[project_name]/.babelrc" at 0, attempted to resolve relative to "/Users/[username]/Documents/htdocs/[project_name]/wp-content/plugins/[project_name]" at /Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17 at Array.map (<anonymous>) at Function.normalisePlugins (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20) at OptionManager.mergeOptions (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36) at OptionManager.init (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12) at File.initOptions (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/index.js:212:65) at new File (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/file/index.js:135:24) at Pipeline.transform (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-core/lib/transformation/pipeline.js:46:16) at transform (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-cli/lib/babel/util.js:50:22) at Object.compile (/Users/[username]/Documents/htdocs/[project_name]_jsx/compiler/node_modules/babel-cli/lib/babel/util.js:59:12)

該当のソースコード

package.json

json

1{ 2 "name": "project_name", 3 "version": "1.0.0", 4 "devDependencies": { 5 "babel-cli": "^6.26.0", 6 "babel-core": "^6.25.0", 7 "babel-plugin-transform-react-jsx": "^6.24.1", 8 "babel-plugin-external-helpers": "^6.0.0", 9 "babel-preset-env": "^1.6.0" 10 }, 11 "dependencies": { 12 "@wordpress/components": "^2.0.1", 13 "create-guten-block": "^1.13.0" 14 } 15} 16

.babelrc

json

1{ 2 "presets": [ 3 [ "env", { 4 "modules": false, 5 "targets": { 6 "browsers": [ 7 "last 2 Chrome versions", 8 "last 2 Firefox versions", 9 "last 2 Safari versions", 10 "last 2 iOS versions", 11 "last 1 Android version", 12 "last 1 ChromeAndroid version", 13 "ie 11" 14 ] 15 } 16 } ] 17 ], 18 "plugins": [ 19 ["external-helpers"], 20 [ "transform-react-jsx", { 21 "pragma": "wp.element.createElement" 22 } ] 23 ] 24}

試したこと

  • node_modules/babel-plugin-external-helpersが存在することを確認

  • とりあえず再起動

  • npmを最新に

bash

1$ sudo npm i -g npm
  • npm updateを実行

bash

1$ npm update
  • pluginのディレクトリで直接npm installを実行

bash

1$ cd node_modules/babel-plugin-external-helpers 2$ npm install
  • .babelrcのpluginの指定方法を変えてみる

json

1"plugins": [ 2 "external-helpers", 3 ... 4 5"plugins": [ 6 "@babel/external-helpers", 7 ... 8 9"plugins": [ 10 ["external-helpers"], 11 ... 12 13"plugins": [ 14 ["@babel/external-helpers"], 15 ... 16

とりあえず

bash

1node_modules/.bin/babel-external-helpers -t var > babelHelper.js

で共通コードのファイルを作る方はできました

よろしくお願いします

補足情報(FW/ツールのバージョンなど)

MacOS 10.15 Catalina

kyoya0819👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

グローバルにインストールしたら動きました

しかしプロジェクトのディレクトリに置いたものは相変わらず認識されません
一応echo $PATHで見る限りPATHの追加はされてるっぽいんですがダメです
iCloud Driveの配下にあるディレクトリにはパスを通せないとかなのか
原因はよくわかりませんが一応動くようにはできたのでしめさせてもらいます

投稿2019/10/29 02:19

KazuhiroHatano

総合スコア7804

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問