Module not found in Node.js environment (webpack)

I seem to be encountering an issue with loading any modules. Despite reinstalling my operating system, I continue to face the same error when attempting to use any module.

I have tried reinstalling node, clearing the cache, and more.

To view the code, please click on the link below.
https://github.com/ziyak9803/Webpack/tree/main

Strangely, everything seems to work fine with older versions of the libraries/modules.

//Working Fine
"devDependencies": {
    "css-loader": "^2.1.0",
    "style-loader": "^0.23.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3"
  }

However, the latest dependencies do not seem to work correctly.

//Not Working
"devDependencies": {
    "css-loader": "^6.5.1",
    "style-loader": "^3.3.1",
    "webpack": "^5.65.0",
    "webpack-cli": "^4.9.1"
  }

index.js

import './style.css';

const headline = "Hello World";
document.querySelector('h1').innerText = headline;

style.css

body {
    background-color: blue;
    color: red;
}

h1 {
    font-size: 3rem;
}

package.json

{
  "name": "webpack-testing",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^6.5.1",
    "style-loader": "^3.3.1",
    "webpack": "^5.65.0",
    "webpack-cli": "^4.9.1"
  }
}

webpack.config.js

const path = require("path");

module.exports = {
  mode: "development",
  entry: "./src/index.js",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, "dist"),
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["css-loader"],
      },
    ],
  },
};

ERROR LOG:

  ../../../#Projects/#Minor/webpack-testing/src/index.js 108 bytes [built] [code generated]
  ../../../#Projects/#Minor/webpack-testing/src/style.css 39 bytes [not cacheable] [built] [code generated] [1 error]

ERROR in ../../../#Projects/#Minor/webpack-testing/src/style.css
Module build failed (from ../../../#Projects/#Minor/webpack-testing/node_modules/css-loader/dist/cjs.js):
Error: Cannot find module 'E:\#Projects\#Minor\webpack-testing\node_modules\css-loader\dist\cjs.js'
Require stack:
- E:\#Projects\#Minor\webpack-testing\node_modules\loader-runner\lib\loadLoader.js
- E:\#Projects\#Minor\webpack-testing\node_modules\loader-runner\lib\LoaderRunner.js
- E:\#Projects\#Minor\webpack-testing\node_modules\webpack\lib\NormalModuleFactory.js
- E:\#Projects\#Minor\webpack-testing\node_modules\webpack\lib\Compiler.js
....

Answer №1

It turns out that the culprit behind the problem was actually the name of my folders/directories. I have a tendency to keep things organized and I used special characters as the first character in the names of important folders so they would appear at the beginning.
For example: #Major !Project as folder names.


The issue was resolved once I removed the special characters from the names of my folders/directories.
For example: Major Project as folder names.

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

Should node_modules be deleted before running npm install?

Should node_modules be removed before running an 'npm install' to ensure a more dependable installation, or does npm simply overwrite existing files? ...

Error in the distribution of Azure BitBucket data

After acquiring a Visual Studio MSDN subscription on the Microsoft Azure Platform, I made the decision to migrate my Heroku Applications to the Azure cloud. I had 3 applications developed in NodeJS and 1 application in PHP. While I successfully deployed ...

When Ionic is installed on a Windows x64 system, it may encounter unexpected errors

While attempting to set up Ionic on my system, I encountered a few obstacles. Firstly, I had to ensure that the Android SDK was installed and properly configure some path variables. After successfully completing those tasks, I proceeded to install Cordova ...

What are the steps for integrating webfont NPM into your project?

//app.js const webfont = require('webfont').default; webfont({ fontName: 'mycustomfont', files: './src/*.ttf', formats: ['woff','eot'] }).then((result) => { console.log(resul ...

Are font classifications determined by the operating system of the viewer or the web browser of the viewer

One thing I've observed is that Google Fonts never uses "fantasy" as a fallback class in the font-family. Instead, they utilize "cursive" for all script and typical fantasy fonts. Could this be a subtle indication that Chrome does not support "fantas ...

Adjust the text within the treeview node for proper alignment

My treeview has nodes that display text, but when the length of the text increases, it moves to the next line and starts one place before the upper text, causing alignment issues. Is there a way to use CSS or JavaScript to properly align the text? Regards ...

Running a nodejs application in the background on a MediaTek 7688 device

I am currently utilizing the Mediatek 7688 board with OpenWRT linux to develop an IoT device. The application has been developed in NodeJS and I need it to run automatically upon booting up the board. Even though I followed the steps provided [here] (How ...

Ways to determine if a script is currently running within Node.js环境

In my Node.js script, I am importing a separate script that I want to be compatible with various JavaScript engines. Specifically, I only want the line exports.x = y; to run if the code is being executed in a Node.js environment. How can I determine this ...

Use CSS to activate a sibling div when hovering over a button within the same div that contains the button

Is it possible to change the color of div #panel when hovering over the button #button inside div #left? #left #button:hover~#panel { background-color: blue; } #panel { position: absolute; float: r ...

Out of the blue, my Nextjs project unexpectedly ceased functioning on my local machine

Lately, I've been working on a Nextjs project locally as per my usual routine. However, out of the blue, the website just stopped functioning on localhost! Every time I checked the console, this error kept showing up: crbug/1173575, non-JS module fil ...

What is the best way to align my SVG to display inline with text?

I am trying to add an SVG image next to some text in a navbar, but I'm running into some issues. The SVG is overflowing from the navbar instead of aligning inline with the text. Here's a snippet of my HTML code: ...

Tips for resolving the error message "cannot find module './node'" when compiling with pkg:

After successfully running my Node.js script with 'node main.js', I encountered an error when trying to compile it into an executable using pkg: pkg/prelude/bootstrap.js:1876 throw error; ^ Error: Cannot find module './node' Require s ...

Having trouble making a basic delete request in Postman

Looking for assistance with a phonebook app built using node.js, express, mongo db, and mongoose. Currently, Get and Post requests are functioning properly, with Post requests being saved in the Mongo database. However, encountering issues with Delete re ...

"Encountered a problem during installation of the zmq module in Node

Encountered an error when attempting to install the zmq package in Node.js: npm http GET http://registry.npmjs.org.org/zmq npm http 200 http://registry.npmjs.org.org/zmq npm ERR! registry error parsing json > <a href="/cdn-cgi/l/email-protection" c ...

Node.js Project Using a Specific URL and Parameter

Two things are on my mind: 1. I'm trying to set up my project's URL as 127.0.0.1:8080/param=id, but I've been unsuccessful so far despite attempting the following: app.get('/param=id', function(req, res) { console.log(req.param ...

Sending error messages from server to client (leveraging Express and Backbone)

I'm struggling with passing server error messages to a client after thrashing around for a while. Here's what I have on the server side (simplified): export function get(req: express.ExpressServerRequest, res: express.ExpressServerResponse) { ...

Changing the color of a div while implementing a show and hide effect in JavaScript

I have designed a checkout system with three distinct parts - shipping information, billing information, and order confirmation. These sections are all on the same page, allowing for a seamless flow during the checkout process. Once a customer completes t ...

NodeJS Server - Implementing Configurations for Multiple URL Rewrites

Seeking to utilize a NodeJS server as a quick fix to test some AngularJS apps that were developed in a .NET environment (running on a mac). Both applications make use of the <base> tag and have rewrite rules in the web.config file to prevent 404 erro ...

Tips on creating a horizontal scrolling effect using the mouse

Is there a way to enable horizontal scrolling by holding down the mouse click, instead of relying on the horizontal scroll bar? And if possible, can the scroll bar be hidden? In essence, I am looking to replicate the functionality of the horizontal scroll ...

Express JS port is active, however unable to terminate the port

When attempting to run nodemon index.js, I encountered an error. Even though PM2 was running, my localhost port 5002 gave me the following error: [nodemon] starting `node index.js` Listening on 5002 events.js:377 throw er; // Unhandled 'error&ap ...