0

ソースファイルに依存関係が必要な場合は機能すると思いnpm install|updateますが、実行可能ファイルを実行したい場合nodemonは動作しないようです。ファイルをグローバルに検索しようとしていますか? これらのコマンドを最初に表示するにはどうすればよいnode_modulesですか?


で開発サーバーを起動する Cakefile がありますnodemon。例えば:

# **`procExec(procName)`**
# returns the path to executable in `node_`
procExec = (procName) -> 
    console.log "./node_modules/" + procName + "/bin/" + procName
    "./node_modules/.bin/" + procName

# **`cake startdev`**
# Starts the server with `nodemon`
# Watch and compile `.coffee` and `.styl` files in `/client`

task "startdev", "Starts server with nodemon and watch files for changes", ->
    # start nodemon server
    nodemon = spawn procExec("nodemon"), ["server.coffee"]
    processOutput nodemon

    # watch and compile CoffeeScript
    coffee = spawn procExec("coffee"), ["-o", "public/js/app", "-cw", "client/coffee"]
    processOutput coffee

    # watch and compile Stylus
    stylus = spawn procExec("stylus"), ["client/stylus", "-l", "-w", "-o", "public/css/app"]
    processOutput stylus

動作しますが、いくつかの小さな問題があります。

  • npm install|updateインストールしていないようですnodemon。グローバルにインストールしようとして失敗したと思います。私は手動でnpm install nodemon個別に行いました。どうしてこれなの?nodemonとにかくインストールするように指示するにはどうすればよいですか?
  • "./node_modules/.bin/" + procName常に正しい実行可能ファイルに解決されますか?
4

1 に答える 1

2

ここにいくつかの質問があるので、それらを分けておきます。

npm install|update は nodemon をインストールしていないようです。グローバルにインストールしようとして失敗したと思います。npm install nodemon を個別に手動で実行しました。どうしてこれなの?とにかくnodemonにインストールするように指示するにはどうすればよいですか?

「グローバル インストールを優先する」という警告が表示されましたか? その場合、それは単なる警告であり、とにかくインストールされていたはずです. 別のエラーであった場合は、出力を含めてください。

"./node_modules/.bin/" + procName は常に正しい実行可能ファイルに解決されますか?

はい、依存関係の package.json ファイルにリストされているスクリプトはすべて、このフォルダーにインストールされます。ただし、npm binコマンドを使用して常に正しいパスを取得することを好みます。

ノードからプロセスを生成している場合はrequire('npm')、修正process.env.PATHして適切なnode_modules/.bin場所に配置することもできます。たとえば、Cakefile の上部に:

npm = require 'npm'
npm.load (err) -> throw err # If config fails to load, bail out early
process.env.PATH = npm.bin + ":" + process.env.PATH
# Now you no longer need to use procExec in your tasks

免責事項そのような PATH の変更が Windows で機能するかどうかはわかりません。

于 2012-08-13T02:52:01.107 に答える