thumb

Recently, when attempting to install the gulp-babel package using the npm CLI (“Node package manager”, “Command line interface”) in the Terminal app, I saw a warning saying gulp-babel@8.0.0 requires a peer of @babel/core@^7.0.0. Then, when attempting to run gulp, I saw an error message saying that gulp run is failed because Cannot find module '@babel/core'. In this tutorial, you’ll learn how to solve this problem. How to fix: npm WARN gulp-babel@8.0.0 requires a peer of @babel/core@

What causes this error

In my case, the below warning message appeared when attempting to install the gulp-babel package using the npm CLI (“Node package manager”, “Command line interface”) in the Terminal app.

$ npm install gulp-babel --save-dev
npm WARN gulp-babel@8.0.0 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself.

+ gulp-babel@8.0.0
added 2 packages from 5 contributors and audited 6639 packages in 3.529s

5 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

And the below error appeared when attempting to run the gulp command inside my app project.

$ gulp
internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module '@babel/core'
Require stack:
- /Users/arthur/GitHub/app/node_modules/gulp-babel/index.js
- /Users/arthur/GitHub/app/gulpfile.js
- /usr/local/lib/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js
- /usr/local/lib/node_modules/gulp-cli/index.js
- /usr/local/lib/node_modules/gulp-cli/bin/gulp.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.\<anonymous\> (/Users/arthur/GitHub/app/node_modules/gulp-babel/index.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/arthur/GitHub/app/node_modules/gulp-babel/index.js',
    '/Users/arthur/GitHub/app/gulpfile.js',
    '/usr/local/lib/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js',
    '/usr/local/lib/node_modules/gulp-cli/index.js',
    '/usr/local/lib/node_modules/gulp-cli/bin/gulp.js'
  ]
}

The warning and error message above are self explanatory. They saying that the gulp run is failed, and this is because it Cannot find module '@babel/core' and gulp-babel@8.0.0 requires a peer of @babel/core@^7.0.0 but none is installed accordingly. Therefore, we just need to install the dependencies ourself to solve the problem.

From the Babel documentation at babeljs.io/docs/en/next/usage:

All the Babel modules you will need are published as separate npm packages scoped under `@babel` (since version 7). This modular design allows for various tools each designed for a specific use case.

...

The core functionality of Babel resides at the `@babel/core` module.

Now we know what caused this error.

How to solve it

Once we know what is causing the gulp run to fail, we can use it to solve the problem. It is a really easy process. To solve this problem, we need to install the '@babel/core' and @babel/preset-env modules. Now, step by step guide.


Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.

How to fix: npm WARN gulp-babel@8.0.0 requires a peer of @babel/core@


Go to the working directory (in this example the my_app_dir catalogue is used) by typing the following command and press the Enter key.

cd ./my_app_dir

Important! In my case the working directory is the catalogue of my app project called my_app_dir where the problem has occurred. Change the command above to suit your case.


Type the following command and press the Enter key to install the '@babel/core' and @babel/preset-env modules inside your working directory.

npm install @babel/core @babel/preset-env --save-dev
+ @babel/core@7.8.4
+ @babel/preset-env@7.8.4
added 123 packages from 31 contributors and audited 8141 packages in 14.653s

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Finally, we can try to run gulp and verify that it runs without the error. For this, type the following command and press the Enter key.

Note! In the command below just the gulp is used. Change the command below to suit your case.

gulp
[03:26:53] Using gulpfile ~/my_app_dir/gulpfile.js
[03:26:53] Starting 'test'...
[03:26:53] Finished 'test' after 22 ms

No errors. It works!

Conclusion

That’s it, you’re done. Now the gulp should run without the npm WARN gulp-babel@8.0.0 requires a peer of @babel/core@ error. So simple isn’t it?

If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!

I hope this article has helped you learn how to fix the node-gyp rebuild error. If this article helped you then please leave a comment :smiley:

Thanks for reading!