升级Node至9.3.0后运行Gulp报错:TypeError: require.extensions.hasOwnProperty is not a function
TypeError: require.extensions.hasOwnProperty is not a function After Upgrading Node to 9.3.0 I’ve dealt with this exact problem before when upgrading Node from pre-v8 versions to v8+ on macOS Sierra, so let’s walk through what’s going on and how to fix it quickly.
What’s Causing This?
Starting with Node.js v8, the team changed how require.extensions works under the hood. It’s no longer a standard JavaScript object that comes with the hasOwnProperty method built-in. Older versions of Gulp (especially Gulp 3.x) and some of its dependent plugins still try to call this method, which throws the TypeError you’re seeing.
Solutions to Try
1. Upgrade Gulp to a Node v8+ Friendly Version
This is the most permanent fix:
- First, update the global Gulp CLI tool:
npm install -g gulp-cli - Then, upgrade the local Gulp package in your project (this will install Gulp 4.x, which fully supports Node v8 and later):
A quick heads-up: If you’re using the old Gulp 3.x task syntax (like passing arrays of tasks), you’ll need to adjust yournpm install gulp@latest --save-devgulpfile.jsto use Gulp 4.x’sgulp.series()andgulp.parallel()functions for task ordering. It’s a small tweak but necessary for everything to work.
2. Downgrade Node to Match Your Current Gulp Setup
If you don’t want to rework your Gulp tasks right now, use a Node version manager to switch back to a version that plays nice with Gulp 3.x:
- Install a tool like
nvm(Node Version Manager) if you don’t have it already. Once it’s set up, you can switch to Node 6.x with:
This lets you keep your existing Gulp setup while still being able to switch to newer Node versions for other projects.nvm install 6 nvm use 6
3. Update Outdated Plugins
Sometimes the issue isn’t Gulp itself, but a specific plugin that’s using the deprecated require.extensions.hasOwnProperty call. To track it down:
- Run this command to see all your project’s dependencies and their versions:
npm ls - Look for plugins that haven’t been updated in a while, then upgrade them to the latest version:
This often fixes the problem without needing to upgrade Gulp entirely.npm install [plugin-name]@latest --save-dev
内容的提问来源于stack exchange,提问作者G-Man

