How to fix node-waf "ImportError: No module named Scripting" on Linux

Issue:

When executing node-waf, you get the following error message:

Traceback (most recent call last):
File "/usr/local/bin/node-waf", line 14, in <module>
import Scripting
ImportError: No module named Scripting

This also prevents node modules with native components to be built.

Solution

You probably use the n NodeJS version mananger. node-waf expects a file named Scripting.py in /usr/local/lib/node/wafdmin/ which is not present in your case.

Unfortunately, n (at least up to version 0.7.3) doesn’t create this file.

To solve the issue, run (replace 0.8.11 by the nodejs version you are currently using. It needs to be managed by n in order to work):

ln -sf /usr/local/n/versions/0.8.11/lib/node/wafadmin/ /usr/local/lib/node/

You can also use this automatic bash script that automatically determines your NodeJS version, assuming node refers to the *n*-managed NodeJS version.

ln -sf /usr/local/n/versions/`node --version | cut -c2-`/lib/node/wafadmin/ /usr/local/lib/node/

Update (13. Jan 2013): Added automatic way of determining the NodeJS version; added ln -f flag to overwrite bad existing links