npm run is having trouble locating the graceful-fs module

I am currently enrolled in a course on DjangoRest and React. While I have experience with npm and Python, I have encountered an error that I am unable to resolve. Everything was going smoothly until I ran "npm run dev."

package.json file

{
  "name": "frontend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development --watch",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.13.16",
    "@babel/preset-env": "^7.13.15",
    "@babel/preset-react": "^7.13.13",
    "babel-loader": "^8.2.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "webpack": "^5.34.0",
    "webpack-cli": "^4.6.0"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@material-ui/core": "^4.11.3",
    "@material-ui/icons": "^4.11.2",
    "react-router-dom": "^5.2.0"
  }
}

webpack.config.js file

const path = require("path");
const webpack = require("webpack");

module.exports = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "./static/frontend"),
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
    ],
  },
  optimization: {
    minimize: true,
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("production"),
      },
    }),
  ],
};

Error

npm run dev

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f0e4f9f8e2f3f8f2d6a7b8a6b8a6">[email protected]</a> dev E:\Programacion cursos\Harvard\React&JavaScript\VsCode\react_django\frontend
> webpack --mode development --watch

"JavaScript\VsCode\react_django\frontend\node_modules\.bin\" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'E:\Programacion cursos\Harvard\webpack\bin\webpack.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9cfdbc6c7ddccc7cde99887998799">[email protected]</a> dev: `webpack --mode development --watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a2b6abaab0a1aaa084f5eaf4eaf4">[email protected]</a> dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

I believe the issue lies in the location where npm is searching for the webpack.js file. The current path of webpack.js is "E:\Programacion cursos\Harvard\React&JavaScript\VsCode\react_django\frontend\node_modules\webpack\bin\webpack.js" but for some reason, it is looking for the module in "E:\Programacion cursos\Harvard\webpack\bin\webpack.js."

I want to change the search path for the webpack module, but I am unsure how to do so. I have tried using "npm link webpack" followed by "npm unlink webpack" to reinstall it, but it did not resolve the issue. If anyone knows how to fix this problem, please offer assistance. Thank you!

Edit I have fixed one of the issues by changing the "node_module\.bin" folder to "node_module\bin."

Within "node_modules," the "graceful-fs" module is present. What steps can I take next? The error message reads:

Error: Cannot find module 'graceful-fs'
Require stack:
- C:\Users\matia\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js       
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\matia\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js:77:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\matia\\AppData\\Roaming\\npm\\node_modules\\webpack\\bin\\webpack.js'
  ]

Answer №1

https://i.sstatic.net/RJxWZ.png

In my current project setup, I am running npm from the directory where all the necessary files are located. This includes npm modules, webpack input, webpack output, webpack config, package.json, and package-lock.json - all within the same directory. Below is an example of my webpack configuration:

var path = require ('path');

module.exports = {
    entry : './webpack-entry',
    mode : 'production',
    output : {
        filename : 'webpack-output.js',
        path : path.resolve(__dirname),
        library : {
            name: 'chartModule',
            type : 'umd'
        }
    },
}

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

Executing a webservice method in an html page using javascript without the need to refresh the page

Is it possible to call a webservice from an index.html page using JavaScript? My webservice is located at "localhost/ws/service.asmx" and the specific web method I want to call is called HelloWorld. The index.html page contains an HTML submit button whic ...

Images uploaded using Django not appearing on the webpage template

I'm having trouble displaying the most recent top 5 files that have been posted. Even though I can retrieve all objects from the database using Model.objects.all(), when I try to get only the top 5, they don't show up. Any suggestions would be gr ...

Tips for creating a webfont using SVG icons

Seeking advice on generating a webfont from SVG icons using webpack, angular2, and typescript. Any suggestions on the best way to achieve this? Struggling to find helpful information online. Please lend a hand! https://i.sstatic.net/kvClK.png The code pr ...

Encountering an issue while trying to pass hidden value data in array format to the server side

I am currently learning how to use Handlebars as my templating engine and encountering an issue with passing over data from an API (specifically the Edamam recipe search API). I am trying to send back the array of ingredients attached to each recipe card u ...

"Help! I'm facing an issue with my PHP PDO insert statement

I've been working on developing a web application that allows users to create new projects, but I've hit a roadblock. For the past couple of days, I've been stuck on a particular issue related to the "New Project" button. When this button i ...

Retrieving Firestore information as a JavaScript object

I'm working on retrieving data from Google Firestore as a JavaScript object in Vue.js (3). It functions correctly when used within a V-for loop, but I also need to utilize the array in methods. How can I convert the Firestore data into a basic JavaScr ...

Having trouble with radio button validation in JS?

I'm having difficulty understanding why the radio button is not staying checked when I select another option. To demonstrate, I created a fiddle where initially the "diy" button is selected but switching to "paid" causes the radio button to jump back ...

What is the process for verifying the password field in bootstrap?

In my asp.net project using bootstrap, I have implemented password field validation. When the user clicks on the password field, an information box is displayed. <div id="pswd_info"> <h4>Password requirements:</h4> <ul> ...

Creating a Vue.js component with dynamic data

Recently, I started working with Vue.js and have been experimenting with it for a few days. One of the challenges I'm facing is trying to dynamically add a new div element with text input every time the enter button is pressed. I would greatly appreci ...

the angular variable scope has not been defined

Currently, I am developing an angular controller that is configured to utilize the "controller as" syntax: angular.module('app', []).controller('ctrl1', ctrl1); ctrl1.$inject = ['$http', '$compile']; function ctrl ...

Error: Call stack limit reached while passing JSON data using Node.js

I am utilizing the ajax-request module to send Json data using a post request in my Node.js application. Below is the relevant code snippet: logMessage : function(url, message, next) { var d1 = message["sender"]; var d2 = { id: message[sender"]["id"], ...

Inject fresh variable values into the serialization process

Within my login form, I have fields for Username and Password. Upon clicking the login button, a Javascript function is triggered to make an ajax request to the login controller. To serialize the form data, I used the code snippet below: var parameters = ...

Distinguishing between a video or image when uploading files in JavaScript

I've been researching whether JavaScript can determine if a file is a video or an image. However, most of the information I found only shows how to accept these types using the input tag. What I really need is for JS to identify the file type and the ...

Encountering an issue where npm cannot determine the executable to run, despite reinstalling Node

As a newcomer to React, I recently installed it for the first time. However, when attempting to create a new project, I encountered an error message: npm ERR! could not determine executable to run I have attempted to reinstall all Node.js related softwa ...

Presenting CSV data in a tabular format using Angular and TypeScript

I am facing an issue with uploading a CSV file. Even though the table adjusts to the size of the dataset, it appears as if the CSV file is empty. Could this be due to an error in my code or something specific about the CSV file itself? I'm still learn ...

Implement a personalized click function for the delete icon in the mini cart

Is there a way to customize the click event for the remove button in the mini cart? function ajax_call(){ $.ajax({ url: ajax_url, type: 'post', data: {action : 'remove_from_cart','cart_item_key' : 10}, ...

Troubleshooting on Mac OSX for EACCES: permission denied...Access to this file is restricted

Attempting to start a new project using the Gatsby template by running the command gatsby new website-public https://github.com/gatsbyjs/gatsby-starter-default in the Terminal window is resulting in an ongoing error: gatsby new website-public https://git ...

Is there a way to trigger the activation of the datepicker during the `onLoad` event?

For my project, I am utilizing this datepicker. While I am familiar with using scripts to handle changes in the date value, I am unsure of how to implement it on page load. $('.date_set .date').datepicker({ startView : 0, ...

Looking for a way to customize the auto_now_add feature in Django when using pytest factory

Is there a way to override the sent_at attribute in pytest factory when using auto_now_add in django models? It seems that the current setup is not working as expected. class ABC(models.Model): x = models.ForeignKey(X, on_delete=models.CASCADE, relat ...

After updating to version 13 of Angular and Angular Material, the mat-contenteditable feature has ceased functioning

Encountered errors with mat-contenteditable after updating Angular from version 12 to 13 Error: /node_modules/mat-contenteditable/lib/mat-ckeditor.directive.d.ts:9:22 - error TS2420: Class 'MatCkeditorDirective' incorrectly implements interface & ...