Issue with Gulpfile.js - cannot locate module

Hey everyone, I'm new to posting so please bear with me...

I've been following a tutorial by Kevin Powell on setting up gulp to automate SCSS compiling and more. You can check out the tutorial here.

I thought I followed all the instructions correctly, but when I try to run the 'gulp style' command, I keep encountering this error:

It seems like the node_modules are set up properly in the root folder after installation, and gulp is listed in the dependencies of package.json.

Any assistance would be greatly appreciated.

Error: Cannot find module 'gulp;'
Require stack:
- C:\Users\Admin\OneDrive\Desktop\test\gulpfile.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\shared\require-or-import.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^3.7.0\index.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\index.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\Admin\OneDrive\Desktop\test\gulpfile.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Admin\\OneDrive\\Desktop\\test\\gulpfile.js',
    'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\lib\\shared\\require-or-import.js',
    'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\lib\\versioned\\^3.7.0\\index.js',
    'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\index.js',
    'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js'
  ]
}

I have already tried deleting node_modules and reinstalling npm, but the issue persists.

Answer №1

If you currently have gulp installed globally, it's recommended to uninstall them using the following command:

run npm rm --global

Afterwards, proceed by installing gulp-cli globally with this command:

npm install --global gulp-cli

Now navigate to your project directory and run the following command:

npm install --save-dev gulp

For more detailed information, please refer to the official gulp documentation here

Answer №2

I'm encountering the same issue as well. It still doesn't seem to be working and I keep receiving the same error message?

Can anyone guide me on where in the gulpfile.js this code snippet needs to be placed:

var gulp = require('gulp');

gulp.task('default', function() {
   // Insert your default task code here
});

Provided below is the content of the gulpfile.js file:

// Required modules initialization
const { src, dest, watch, series } = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const babel = require("gulp-babel");
const terser = require("gulp-terser");
const browsersync = require("browser-sync").create();

// Using dart-sass for @use
//sass.compiler = require('dart-sass'); *******

// Sass Task
function scssTask() {
    return src("app/scss/style.scss", { sourcemaps: true })
        .pipe(sass())
        .pipe(postcss([autoprefixer(), cssnano()]))
        .pipe(dest("dist", { sourcemaps: "." }));
}

// JavaScript Task
function jsTask() {
    return src("app/js/script.js", { sourcemaps: true })
        .pipe(babel({ presets: ["@babel/preset-env"] }))
        .pipe(terser())
        .pipe(dest("dist", { sourcemaps: "." }));
}

// Browsersync Initialization
function browserSyncServe(cb) {
    browsersync.init({
        server: {
            baseDir: "."
        },
        notify: {
            styles: {
                top: "auto",
                bottom: "0"
            }
        }
    });
    cb();
}
function browserSyncReload(cb) {
    browsersync.reload();
    cb();
}

// Watch Task
function watchTask() {
    watch("*.html", browserSyncReload);
    watch(["app/scss/**/*.scss", "app/**/*.js"], series(scssTask, jsTask, browserSyncReload));
}

// Default Gulp Task
exports.default = series(scssTask, jsTask, browserSyncServe, watchTask);

// Build Gulp Task
exports.build = series(scssTask, jsTask);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize CamelCase in jQuery for Better Code Readability

Upon examining the jQuery source code, I noticed an interesting use of camelcase: camelCase: function( string ) { return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); } // where: rmsPrefix = /^-ms-/, rdashAlpha = /-([\da- ...

Instantly summing up two numbers with javascript

In my web development work using Visual Studio 2008, I encountered an interesting challenge. On a webpage, I have three textboxes labeled "Price," "Quantity," and "Amount." The task at hand is to calculate the value of "Amount" by multiplying the values ...

The process of installing dependencies recursively using pnpm

In my monorepo project, I have workspaces A and B. Workspace A depends on B being built first, with each workspace in its own folder as defined in pnpm-workspace.yaml packages: - 'src/mydepa' - 'src/mydepb' { "name": &qu ...

The unprojection of the vector in Threejs from this camera has not been defined

Why am I encountering a "function is undefined" error for vector.unproject even though it is clearly mentioned in the documentation? You can find it here: (one of the last items) Even after console logging it, the function still returns as undefined, des ...

Guide to ensuring every request in an Express.js application contains a cookie

Currently, I am in the process of developing a CRUD application using both React and Node. As part of my development, it is crucial for me to validate whether the cookie is present or not for each request. app.all("*", (req,res) => { // If the cookie ...

Having trouble transferring sound files to Cloudinary API through javascript

I have successfully implemented a function in my React Native application to upload images to Cloudinary. Now, I am trying to modify the function to upload audio files as well. Despite specifying the "resource_type" parameter as "raw", "video", or "auto", ...

Encountered an issue during installation: Error message states that Typings command was not

I've encountered permission errors with npm, so I decided to reinstall it. However, I'm facing an issue with the 'typings' part where it displays a 'typings: command not found' error. This problem seems to be related to Angula ...

Is it possible to merge neighboring text nodes within the DOM using JavaScript?

If I come across a sentence within the webpage's DOM that includes 3 separate text nodes followed by additional elements like BOLD or ITALIC, is there a simple method to merge these text nodes into one? Having adjacent text nodes serves no purpose and ...

Hiding Bootstrap Popover When User Clicks Outside of it

My webpage has dynamically loaded content featuring popovers which need to be bound to the body for correct loading and appearance. I am looking for a solution to hide the popovers when a user clicks outside them or on another popover trigger. After some ...

Locate items across three different arrays

Is there a more efficient way to search for an element across 3 arrays and create a string using their values? I have attempted a solution and generated the output, but I am curious if there is a better approach available. var numbers = ['1',&ap ...

Is it possible to only set style.marginLeft one time?

My navigation menu is positioned off-screen to the right, and I am able to hide it by adjusting the style.marginLeft property. However, when I try to reveal it by setting the property again, nothing happens. function navroll(state) { if(state == true) ...

How can I add seconds to the jquery datetimepicker plugin?

Looking to implement the datetimepicker plugin from here, but I'm having trouble finding information on how to include the seconds part. Is there a way to add seconds to this plugin? It's a crucial requirement, so any suggestions for another good ...

Sharing specific information with a particular component instance in React using .map

I have set up multiple instances of a child component within a parent component using the following code: render() { return ( {this.state.accounts.map(account => <EachAccount key={account.id} curAccountData={account} /> ...

Does ng-class really allow the assignment operator? Could this be a bug or a hidden feature?

Noticed recently that the ng-class allows for assignment operators - is this a bug or a feature? <li ng-repeat="cat in cats" ng-class="{active: cat = 'some-text'}">{{cat}}</li> The correct usage would be: <li ng-repeat="cat in c ...

access the data in the fresh window.open

I created a brand new window var win = window.open("", "", "width=400, height=200"); and now I want to access its body using var $windowBody = $(win.document.body); and then use functions like .find() and .html() While this method works smoothly on Fi ...

What is the most effective method for sorting through vast amounts of data with Javascript, React, and Redux?

Currently, I am working with a minimum JSON data set of 90k [...] and utilizing the .filter method. Everything is functioning correctly without any issues, however, from a performance standpoint, I am curious about potential improvements. Any suggestions o ...

What is more costly in terms of performance: toggling the visibility of a DOM node or adding/removing a DOM node?

When it comes to calling, which is the more costly operation? Displaying and hiding a DOM node Creating and deleting DOM nodes Let's assume we only have one or a few (less than 5) nodes that require manipulation, and the application is running on a ...

The StrongLoop ng-lb command encounters issues when utilizing the local-storage-connector

Hello Strongloop community, I have been experimenting with the local-storage data store example provided by loopback. It's working well and I can successfully create and retrieve files from the local file system (used as a data source) using the REST ...

What is the method to determine the size of an array of objects where each object contains its own internal array?

Here is the data that I have: var a=[ { name: "time", Details:[ {value:"month",checked:true,id:1} ] }, { name: "product", Details:[ {value: ...

Enhance chat functionality by integrating MySQL database to store and update chat messages

I'm currently working on developing a chat system that allows users to enter the chat and send messages. The messages are being stored in a MySQL database, and here is a snippet of my code... <script> $('input[type=text]').on('ke ...