khinester khinester - 1 month ago 19
Node.js Question

webpack use correct node version

in my node project I have a makefile similar to

SHELL:=/bin/bash --login

PROJECT_NAME = Webapp
PROJECT_URL = https://github.com/nkhine/myapp

# Name variables
BUILD_ASSETS = $(wildcard ./build/*.*)
dev: node_modules
GIT_DESCRIBE=`git describe --long --tags --dirty --always` \
nvm exec node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.dev.config.js


on my dev machine i have installed nvm and all seem to work correctly

$ node --version
v4.2.4


but when I run

$ make dev
GIT_DESCRIBE=`git describe --long --tags --dirty --always` \
nvm exec node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.dev.config.js
Running node v6.2.0 (npm v3.8.9)


And then I get

[975] ./~/style-loader/addStyles.js 7.15 kB {1} [built]
+ 3 hidden modules

ERROR in Missing binding /home/khine/Sandboxes/webapp/node_modules/node-sass/vendor/linux-x64-48/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 6.x

Found bindings for the following environments:
- Linux 64-bit with Node.js 4.x

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to build the binding for your current environment.
@ ./~/styleguide/src/styles/styles.scss 4:14-715 13:2-17:4 14:20-721


How do I force webpack to use the nvm version of node?

Running
node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.dev.config.js
works fine

Answer

Add nvm use v4.2.4, like

nvm use v4.2.4 && \
node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.dev.config.js