Running r.js from through node.js within Rake causes a file lock error

I am using Rake to run the r.js optimizer within node. This is the rake command

sh %{node.exe lib/dist/requireJS/2.1.1/r.js -o app.build.js} do |ok, status|
    ok or fail "r.js build failed"
end

This causes the following error

node.exe lib/dist/requireJS/2.1.1/r.js -o app.build.js
Error: EBUSY, resource busy or locked
    at Object.fs.readSync (fs.js:381:19)

If I run the same command outside of rake at the command line I don't get the error. This looks like a file lock error, but I don't know what file is locked or why it is locked. Perhaps it is even a red herring. I would appreciate any insights that you may have.

Thanks in advance