Thursday, March 19, 2015

Simple fix for Module did not self-register

If you see the following error ...

Module did not self-register Error


[18:28:09] Error in plugin 'gulp-mocha'
Message:
    Module did not self-register.
Stack:
Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at bindings (/Users/lex/myproject/node_modules/jsdom/node_modules/contextify/node_modules/bindings/bindings.js:76:44)
    at Object. (/Users/lex/myproject/node_modules/jsdom/node_modules/contextify/lib/contextify.js:1:96)
    at Module._compile (module.js:460:26)
    at Module._extensions..js (module.js:478:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/lex/myproject/node_modules/6to5/lib/6to5/api/register/node.js:113:7)
[18:28:10] Finished 'scripts' after 21 s


Simple fix

... simply remove the node_modules directory and reinstall your npm modules.

/Users/lex/myproject/ $ rm -rf node_modules/
/Users/lex/myproject/ $ npm install


References

https://www.npmjs.com/


Share this article



This work is licensed under the Creative Commons Attribution 3.0 Unported License.

Recursively change file extension

Here's a technique you can use to recursively change the file extension of all files with a particular file extension, e.g., ".txt", to another one, e.g., ".js".

It leverages another technique discussed in the Process Array of Values in Bash Shell post.

It's a one liner, assuming you have a change-file-ext script.

One liner


$ for dir in "${dirs[@]}"; do (cd "$dir"; change-file-ext txt js)  ; done


change-file-ext script


#!/usr/bin/env ruby

# filename:  change-file-ext
# author:    Lex Sheehan
# copyright: Lex Sheehan LLC
# license:   GPL
# status:    production
# comments:  changes file extensions in current directory

def usage
  puts 'Usage:   change-file-ext  '
  puts 'Example: change-file-ext "css.erb" "css"'
  exit
end

if ARGV.size < 2 || ARGV.include?('--h')
  usage
else
  from_ext = "*.#{ARGV[0]}"
  to_ext = ARGV[1]
end

Dir.glob(from_ext).each{|i| `mv #{i} #{i.slice(0..-from_ext.size)}.#{to_ext}` }


References

http://lexsheehan.blogspot.com/2014/05/process-array-of-values-in-bash-shell.html


Share this article



This work is licensed under the Creative Commons Attribution 3.0 Unported License.