TypeError: require.extensions.hasOwnProperty is not a function - on running gulp

4.1k views Asked by At

I was trying to run gulp inside my project directory. I have gone through so many articles. Also try running most of given commands (as solutions) in cmd. But the same problem occurs.

if (!require.extensions.hasOwnProperty(ext)) {
                         ^
TypeError: require.extensions.hasOwnProperty is not a function

This is how my package.json looks like.

{
  "private": true,
  "devDependencies": {
    "gulp": "^3.9.1",
    "laravel-elixir": "^2.3.13"
  },
  "dependencies": {
    "bower": "^1.5.2",
    "require-dir": "^1.2.0"
  }
}

It would be great if anyone can help me to solve this.

2

There are 2 answers

2
Gayan S. Muthukumarana On BEST ANSWER

Finally found an answer. I just changed the below code line in <project>/node_modules/laravel-elixir/node_modules/require-dir/index.js file.

if (!require.extensions.hasOwnProperty(ext)) {

as:

if (!Object.prototype.hasOwnProperty.call(require.extensions, ext)) {

And it finally works now.

0
POK On

I fixed this by using a lesser version of node. I was getting this error when using node v 8.9.1. Fixed it by downgrading to 6.5.0. I use NVM to swap behind versions