Browserify构建在我的package.json依赖项中使用本地版本的npm模块失败

时间:2014-12-16 11:30:34

标签: node.js npm browserify

我已设法设置package.json并使用browserify将我的应用依赖项构建到一个包中,但是,当我尝试切换其中一个依赖项时分叉本地副本构建失败。

这适用于安装上游版本(省略其他模块):

"dependencies": {"react-bootstrap": "0.13.0"}

我的fork的本地路径失败:

"dependencies": {"react-bootstrap": "/home/tom/dev/react-bootstrap/"}

正如使用npm link一样,这似乎是"正确的"以最小的麻烦管理本地版本的方式。

最后,使用我的fork的git url也失败了:

"dependencies": {"react-bootstrap": "git://github.com/tompaton/react-bootstrap.git"}

我尝试更新package.json模块中的react-bootstrap,以便存储库网址指向tompaton/react-bootstrap,但这并没有任何区别。

我得到的错误信息并没有说明情况:

(cycles)tom@neon:~/dev/flask_projects/cycles!$ npm run build

> Cycles@1.0.0 build /home/tom/dev/flask_projects/cycles
> browserify -r react-bootstrap -o static/lib-runtime.js

Error: Cannot find module 'react-bootstrap' from '/home/tom/dev/flask_projects/cycles'
    at /home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:50:17
    at process (/home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:119:43)
    at /home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:128:21
    at load (/home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:43)
    at /home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:66:22
    at /home/tom/dev/flask_projects/cycles/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:107:15)

npm ERR! Cycles@1.0.0 build: `browserify -r react-bootstrap -o static/lib-runtime.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Cycles@1.0.0 build script.
npm ERR! This is most likely a problem with the Cycles package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     browserify -r react-bootstrap -o static/lib-runtime.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls Cycles
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.13.0-43-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "run" "build-runtime"
npm ERR! cwd /home/tom/dev/flask_projects/cycles
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/tom/dev/flask_projects/cycles/npm-debug.log
npm ERR! not ok code 0

/home/tom/dev/flask_projects/cycles/npm-debug.log具有相同的信息。

node_modules文件夹如下所示:

(cycles)tom@neon:~/dev/flask_projects/cycles!$ ls -al node_modules/react-bootstrap/
total 64
drwxrwxr-x  7 tom tom 4096 Dec 16 22:00 .
drwxrwxr-x 14 tom tom 4096 Dec 16 22:00 ..
drwxr-xr-x  6 tom tom 4096 Dec 16 22:00 docs
-rw-r--r--  1 tom tom 3886 Dec 16 22:00 Gruntfile.js
drwxr-xr-x  3 tom tom 4096 Dec 16 22:00 ie8
-rw-r--r--  1 tom tom  228 Dec 16 22:00 .jshintrc
-rw-r--r--  1 tom tom  425 Dec 16 22:00 karma.ci.js
-rw-r--r--  1 tom tom  390 Dec 16 22:00 karma.dev.js
-rw-r--r--  1 tom tom 1123 Dec 16 22:00 LICENSE
-rw-r--r--  1 tom tom  146 Dec 16 22:00 .npmignore
-rw-r--r--  1 tom tom 3596 Dec 16 22:00 package.json
-rw-r--r--  1 tom tom 1345 Dec 16 22:00 README.md
drwxr-xr-x  3 tom tom 4096 Dec 16 22:00 src
drwxr-xr-x  3 tom tom 4096 Dec 16 22:00 test
drwxr-xr-x  5 tom tom 4096 Dec 16 22:00 tools
-rw-r--r--  1 tom tom   37 Dec 16 22:00 .travis.yml

所以npm install已经下载了正确的版本,权限也没问题。

谁能告诉我如何解决这个问题?或者至少指出我有关实际错误的更好信息?

1 个答案:

答案 0 :(得分:0)

使用browserify运行gulpNODE_PATH=./node_modules任务,如下所示:

NODE_PATH=./node_modules gulp scripts

这将告诉node-resolvebrowserify使用该本地文件夹解析其所有依赖项。