npm installでのエラーについて。
1. package.jsonの作成
指定のディレクトリにてコマンドプロンプトを起動し、コマンドプロンプト上で
npm init -y
とすると、以下のメッセージが表示される。
ここで、今回は、G:\JavaScript\cui_sampleが作業フォルダである。
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. G:\JavaScript\cui_sample>npm init -y This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sane defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. name: (cui_sample) version: (0.0.0) description: entry point: (index.js) test command: git repository: keywords: author: license: (BSD) About to write to G:\JavaScript\cui_sample\package.json: { "name": "cui_sample", "version": "0.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "BSD" } Is this ok? (yes)OKなのでEnterキーを入力すると、package.jsonが作成される。
ちなみに、”指定のディレクトリにてコマンドプロンプトを起動”は、エクスプローラーで指定のディレクトリに移動し、そこでアドレスバーにcmdと入力すればよい(少し便利)。コマンドプロンプトを起動してからcdコマンドで指定のディレクトリまで移動してもよい。2. 次に必要なモジュールをインストールする。
試しにencoding-japaneseモジュールをインストールしてみる。
npm install encoding-japanese --saveここで、「CUI_sample」という大文字を含むフォルダ名にしていたところ、invalid nameエラーとなった。
どうやら大文字が含まれるフォルダ名は対応していないようだ。注意しておく必要がある。Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. G:\JavaScript\02_data\01_CUI_sample>npm install encoding-japanese npm ERR! Error: Invalid name: "01_CUI_sample" npm ERR! at ensureValidName (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:281:15) npm ERR! at Object.module.exports.fixNameField (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:196:5) npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:29:38 npm ERR! at Array.forEach (native) npm ERR! at normalize (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:28:15) npm ERR! at final (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:310:33) npm ERR! at then (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:124:33) npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:284:48 npm ERR! at fs.js:207:20 npm ERR! at Object.oncomplete (fs.js:107:15) npm ERR! If you need help, you may report this log at: npm ERR! <http://github.com/isaacs/npm/issues> npm ERR! or email it to: npm ERR! <npm-@googlegroups.com> npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "encoding-japanese" npm ERR! cwd G:\JavaScript\02_data\01_CUI_sample npm ERR! node -v v0.10.13 npm ERR! npm -v 1.3.2 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! G:\JavaScript\02_data\01_CUI_sample\npm-debug.log npm ERR! not ok code 0正しくインストールされれば以下のようなメッセージが表示され、指定したディレクトリ(フォルダ内)にモジュールがインストールされる。
G:\JavaScript\cui_sample>npm install encoding-japanese --save npm http GET https://registry.npmjs.org/encoding-japanese npm http 200 https://registry.npmjs.org/encoding-japanese npm http GET https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-1.0.28.tgz npm http 200 https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-1.0.28.tgz encoding-japanese@1.0.28 node_modules\encoding-japanese