| [81bc7da] | 1 | When using `node-gyp` you might see an error like this when attempting to compile/install a node.js native addon:
|
|---|
| 2 |
|
|---|
| 3 | ```
|
|---|
| 4 | $ npm install bcrypt
|
|---|
| 5 | npm http GET https://registry.npmjs.org/bcrypt/0.7.5
|
|---|
| 6 | npm http 304 https://registry.npmjs.org/bcrypt/0.7.5
|
|---|
| 7 | npm http GET https://registry.npmjs.org/bindings/1.0.0
|
|---|
| 8 | npm http 304 https://registry.npmjs.org/bindings/1.0.0
|
|---|
| 9 |
|
|---|
| 10 | > bcrypt@0.7.5 install /home/ubuntu/public/song-swap/node_modules/bcrypt
|
|---|
| 11 | > node-gyp rebuild
|
|---|
| 12 |
|
|---|
| 13 | gyp ERR! configure error
|
|---|
| 14 | gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
|
|---|
| 15 | gyp ERR! stack at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:69:16)
|
|---|
| 16 | gyp ERR! stack at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:56:37)
|
|---|
| 17 | gyp ERR! stack at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:219:20)
|
|---|
| 18 | gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:105:9
|
|---|
| 19 | gyp ERR! stack at ChildProcess.exithandler (child_process.js:630:7)
|
|---|
| 20 | gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17)
|
|---|
| 21 | gyp ERR! stack at maybeClose (child_process.js:730:16)
|
|---|
| 22 | gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:5)
|
|---|
| 23 | gyp ERR! System Linux 3.5.0-21-generic
|
|---|
| 24 | gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
|
|---|
| 25 | gyp ERR! cwd /home/ubuntu/public/song-swap/node_modules/bcrypt
|
|---|
| 26 | gyp ERR! node -v v0.11.2-pre
|
|---|
| 27 | gyp ERR! node-gyp -v v0.9.5
|
|---|
| 28 | gyp ERR! not ok
|
|---|
| 29 | npm ERR! bcrypt@0.7.5 install: `node-gyp rebuild`
|
|---|
| 30 | npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
|
|---|
| 31 | npm ERR!
|
|---|
| 32 | npm ERR! Failed at the bcrypt@0.7.5 install script.
|
|---|
| 33 | npm ERR! This is most likely a problem with the bcrypt package,
|
|---|
| 34 | npm ERR! not with npm itself.
|
|---|
| 35 | npm ERR! Tell the author that this fails on your system:
|
|---|
| 36 | npm ERR! node-gyp rebuild
|
|---|
| 37 | npm ERR! You can get their info via:
|
|---|
| 38 | npm ERR! npm owner ls bcrypt
|
|---|
| 39 | npm ERR! There is likely additional logging output above.
|
|---|
| 40 |
|
|---|
| 41 | npm ERR! System Linux 3.5.0-21-generic
|
|---|
| 42 | npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "bcrypt"
|
|---|
| 43 | npm ERR! cwd /home/ubuntu/public/song-swap
|
|---|
| 44 | npm ERR! node -v v0.11.2-pre
|
|---|
| 45 | npm ERR! npm -v 1.2.18
|
|---|
| 46 | npm ERR! code ELIFECYCLE
|
|---|
| 47 | npm ERR!
|
|---|
| 48 | npm ERR! Additional logging details can be found in:
|
|---|
| 49 | npm ERR! /home/ubuntu/public/song-swap/npm-debug.log
|
|---|
| 50 | npm ERR! not ok code 0
|
|---|
| 51 | ```
|
|---|
| 52 |
|
|---|
| 53 | The main error here is:
|
|---|
| 54 |
|
|---|
| 55 | ```
|
|---|
| 56 | Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
|
|---|
| 57 | ```
|
|---|
| 58 |
|
|---|
| 59 | This error is caused when you attempt to compile a native addon using a version of node.js with `-pre` at the end of the version number:
|
|---|
| 60 |
|
|---|
| 61 | ``` bash
|
|---|
| 62 | $ node -v
|
|---|
| 63 | v0.10.4-pre
|
|---|
| 64 | ```
|
|---|
| 65 |
|
|---|
| 66 | ## How to avoid (the short answer)
|
|---|
| 67 |
|
|---|
| 68 | To avoid this error completely just use a stable release of node.js. i.e. `v0.10.4`, and __not__ `v0.10.4-pre`.
|
|---|
| 69 |
|
|---|
| 70 | ## How to fix (the long answer)
|
|---|
| 71 |
|
|---|
| 72 | This error happens because `node-gyp` does not know what header files were used to compile your "pre" version of node, and therefore it needs you to specify the node source code directory path using the `--nodedir` flag.
|
|---|
| 73 |
|
|---|
| 74 | For example, if I compiled my development ("pre") version of node.js using the source code in `/Users/nrajlich/node`, then I could invoke `node-gyp` like:
|
|---|
| 75 |
|
|---|
| 76 | ``` bash
|
|---|
| 77 | $ node-gyp rebuild --nodedir=/Users/nrajlich/node
|
|---|
| 78 | ```
|
|---|
| 79 |
|
|---|
| 80 | Or install an native addon through `npm` like:
|
|---|
| 81 |
|
|---|
| 82 | ``` bash
|
|---|
| 83 | $ npm install bcrypt --nodedir=/Users/nrajlich/node
|
|---|
| 84 | ```
|
|---|
| 85 |
|
|---|
| 86 | ### Always use `--nodedir`
|
|---|
| 87 |
|
|---|
| 88 | __Note:__ This is for advanced users who use `-pre` versions of node more often than tagged releases.
|
|---|
| 89 |
|
|---|
| 90 | If you're invoking `node-gyp` through `npm`, then you can leverage `npm`'s configuration system and not have to specify the `--nodedir` flag all the time:
|
|---|
| 91 |
|
|---|
| 92 | ``` bash
|
|---|
| 93 | $ npm config set nodedir /Users/nrajlich/node
|
|---|
| 94 | ``` |
|---|