Pro AngularJS をみて AngularJS を勉強している最中なのですが、本題に入る前の以下の node スクリプトが動きません。
var connect = require('connect');
connect.createServer(
connect.static("../angularjs")
).listen(5000);
エラーは以下の通り。
pollux:pro-angularjs ohisa$ node server.js
/Users/ohisa/git/github/pro-angularjs/server.js:3
connect.static("../angularjs")
^
TypeError: Object function createServer() {
function app(req, res, next){ app.handle(req, res, next); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} has no method 'static'
at Object. (/Users/ohisa/git/github/pro-angularjs/server.js:3:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
pollux:pro-angularjs ohisa$
手元の環境は Mac 上の homebrew で構築していて以下のような構成
pollux:pro-angularjs ohisa$ npm list
/Users/ohisa
├─┬ connect@3.0.2
│ ├─┬ debug@1.0.3
│ │ └── ms@0.6.2
│ ├─┬ finalhandler@0.0.2
│ │ ├─┬ debug@1.0.2
│ │ │ └── ms@0.6.2
│ │ └── escape-html@1.0.1
│ ├── parseurl@1.1.3
│ └── utils-merge@1.0.0
└─┬ serve-static@1.3.2
├── escape-html@1.0.1
├── parseurl@1.1.3
└─┬ send@0.6.0
├── debug@1.0.3
├── depd@0.3.0
├─┬ finished@1.2.2
│ └── ee-first@1.0.3
├── fresh@0.2.2
├── mime@1.2.11
├── ms@0.6.2
└── range-parser@1.0.0
pollux:pro-angularjs ohisa$
原因は connect のバージョンが 3 になり、かなり API が変わってしまったためでした。まぁ、保守サポートがあるわけでもないのでしかたないところですが、この辺は最先端 (細い枝) ということで受け入れるしかないのかも知れませんね。
なお、Stack Overflow の ここ や ここ が参考になりました。
修正したスクリプトはこちら
var connect = require('connect');
var serveStaic = require('serve-static');
var app = connect();
app.use(serveStaic("../angularjs"));
app.listen(5000);
事前に serve-static モジュールをインストールする必要があります。
$ npm install serve-static

0 コメント:
コメントを投稿