KeystoneJS で CMS を作成してみようと遊び始めたところ、問題にぶつかってしまったので共有します。
- OS: Windows 10 64bit (1909)
- Node.js: v.12.13.1
- Node.js のバージョン選択: nvm-windows 1.1.7
- Chocolatey 経由でインストール
- 以前は Nodist を使用
- yarn: 1.12.1
- コマンドライン: Cmder 1.3.13.967
現象
yarn create (アプリケーション名)
でアプリケーションを作成しましたが、下記のエラーにぶつかってしまい、アプリケーションディレクトリごと作成できていませんでした。
> yarn create keystone-app sample-app yarn create v1.21.1 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.4: The platform "win32" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "create-keystone-app@1.5.0" with binaries: - create-keystone-app 'C:\Program' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。 error Command failed. Exit code: 1 Command: C:\Program Files (x86)\Nodist\bin\bin\create-keystone-app Arguments: sample-app Directory: D:\aokashi\Documents\Bitbucket Output: info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
原因
ホームディレクトリにある .npmrc を削除することで正しく動作できました。
.npmrc には以前使用していた Nodist のグローバルパッケージのパスが含まれていて、そこから参照しようとしていました。
解決までの道のり
まず、 「'C:\Program' は、内部コマンドまたは外部コマンド、操作可能なプログラムまたはバッチ ファイルとして認識されていません。」 とそのまま検索しましたが、目的の記事が見つかりませんでした。
ただし、このエラーの中には実行している create-keystone-app
の PATH が含まれているんですが、その中に Nodist
が含まれていました。現在は Node.js のバージョン選択に nvm-windows を使用していますが、以前は Nodist を使用していました。その関係で、 Nodist 関係のファイルが含まれていたのです。
そこで、
- PATH から Nodist が含まれているディレクトリを削除
C:\Program Files (x86)
から Nodist ディレクトリを削除- yarn を再度 Chocolatey でインストール
としましたが、今後は
> yarn create keystone-app sample-app yarn create v1.21.1 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.4: The platform "win32" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "create-keystone-app@1.4.1" with binaries: - create-keystone-app error An unexpected error occurred: "EPERM: operation not permitted, mkdir 'C:\\Program Files (x86)\\Nodist'". info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\aokashi\\AppData\\Local\\Yarn\\Data\\global\\yarn-error.log". info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
と出力されました。
えっ、なんで nvm-windows のこと無視して Nodist と認識しているの?意味分からなくない?
そこで、「"EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Nodist'".」と検索しましたが、記事が1件しか表示されませんでした。ひとまず、下記のWebページを頼りに yarn cache clean
を実行しました。
しかしながら、それでも結果は変わりませんでした。
ここで、 yarn で繋がっている Node の実行パスを調べました。
> yarn global bin C:\Program Files (x86)\Nodist\bin\bin
ちなみに、 npm だと
> npm bin -g Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Nodist' TypeError: Cannot read property 'get' of undefined at errorMessage (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-message.js:38:39) at errorHandler (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:201:13) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\bin\npm-cli.js:78:20 at cb (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\npm.js:225:22) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\npm.js:263:24 at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:81:7 at Array.forEach (<anonymous>) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:80:13 at f (C:\ProgramData\nvm\v12.13.1\node_modules\npm\node_modules\once\once.js:25:25) at afterExtras (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:171:20) C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:97 var doExit = npm.config.loaded ? npm.config.get('_exit') : true ^ TypeError: Cannot read property 'loaded' of undefined at exit (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:97:27) at process.errorHandler (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:216:3) at process.emit (events.js:210:5) at process._fatalException (internal/process/execution.js:150:25) Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Nodist' TypeError: Cannot read property 'get' of undefined at errorMessage (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-message.js:38:39) at errorHandler (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:201:13) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\bin\npm-cli.js:78:20 at cb (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\npm.js:225:22) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\npm.js:263:24 at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:81:7 at Array.forEach (<anonymous>) at C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:80:13 at f (C:\ProgramData\nvm\v12.13.1\node_modules\npm\node_modules\once\once.js:25:25) at afterExtras (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\config\core.js:171:20) C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:97 var doExit = npm.config.loaded ? npm.config.get('_exit') : true ^ TypeError: Cannot read property 'loaded' of undefined at exit (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:97:27) at process.errorHandler (C:\ProgramData\nvm\v12.13.1\node_modules\npm\lib\utils\error-handler.js:216:3) at process.emit (events.js:210:5) at process._fatalException (internal/process/execution.js:150:25)
・・・🤔
これについて「Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Nodist'」で検索したところ、今回の問題に該当するWebページが数件見つかりました。前回も同じ検索をしたのに、どうして?と思いましたが、 "
(ダブルクォーテーション) が含まれたことで、エラーの文字列が完全一致として扱ってしまったそうです。
下記の質問で .npmrc
のファイルが残っているとの回答が見つかりました。
なるほど、 .npmrc
の設定が悪かったのか。実際に開いてみると、予想通り Nodist の実行パスのままでした。
> cat .npmrc prefix=C:\Program Files (x86)\Nodist\bin
特に Node のグローバルパスの設定にこだわる必要は無いため、そのまま .npmrc
を削除しました。再度実行したところ、正しく表示されました。👏
> npm bin -g C:\Program Files\nodejs > yarn global bin C:\Users\aokashi\AppData\Local\Yarn\bin > λ yarn create keystone-app sample-app yarn create v1.21.1 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.4: The platform "win32" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "create-keystone-app@1.5.0" with binaries: - create-keystone-app ╦╔═ ╔═╗ ╦ ╦ ╔═╗ ╔╦╗ ╔═╗ ╔╗╔ ╔═╗ ╦ ╔═╗ ╠╩╗ ║╣ ╚╦╝ ╚═╗ ║ ║ ║ ║║║ ║╣ ║ ╚═╗ ╩ ╩ ╚═╝ ╩ ╚═╝ ╩ ╚═╝ ╝╚╝ ╚═╝ ╚╝ ╚═╝ Answer a few questions and we'll generate a starter project for you. ? What is your project name? »
気を付けたいところ
検索の "
には気をつけましょう。 (含まれていると含まれていないでは、検索結果がだいぶ違う)
あとは、ソフトウェアを開発している側であれば、エラー文字列に "
を含めないといった配慮があると良さそうだと感じました。