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

Div element remains fixed in width while zooming in

I'm encountering an issue with a centered div, where the width is set to 50% and the max-width is set to 100%. When I zoom in, the width remains constant but the height increases. Despite setting the max-width to 100%, why does this occur? And most im ...

Issue with regex replacement behaving differently in Node compared to console

I am having trouble properly escaping commas in a sentence. Oddly enough, my replace method is not functioning correctly in node, while it works fine in the Chrome console. Is there anyone who has a solution to this issue? It seems to be occurring with al ...

Is there a way to prevent links from opening in an iframe and have them open in the main window instead?

Imagine you have an iframe on your webpage: <iframe style="border-radius:15px;" width="190" height="450" frameborder="0" scrolling="no" marginheight="5" marginwidth="10" src="../img/interactive_map/interactive_sverige.htm"> </iframe> ...

Blurry text can be a common occurrence when applying the transform(-50%,-50%) function to center

I have found a way to center a section using the following code: <div class="clock-section"> <h5 id="clock-title">We will be arriving soon</h5> <hr class="hr" id="cdhr"> </div> Here is ...

Encountered a session.socket.io error: unable to find session using the provided key: connect.sid

So, I've been struggling with an issue for the past couple of days and I can't seem to figure it out. I've searched through various resources like this GitHub issue and Stack Overflow, but I still haven't found a solution. Here's m ...

The second entry is not being styled by CSS, is there an issue with the code in this section?

I am facing a challenge while trying to set the same background image for two div elements: .abc { background: url('images/autogen.png') no-repeat 0px -133px; width: 256px; height: 256px; }; .def { background: url('images/autogen.png' ...

How can React Components be imported into a website that is not built with React?

After developing a site with Node and Express, I am looking to incorporate a page built with React and JSX. As part of this process, I have installed Babel as an npm package and included React in the index.html file like so: <script src="https://un ...

What is the best way to handle images overflowing a div

I am currently working on creating a carousel using React, where the content images are aligned horizontally. If I have 3 image tags within a div with a width of 1200px, how can I effectively control these images to ensure they fit within the container div ...

TypeOrm is struggling to identify the entities based on the directory path provided

Currently, I am utilizing TypeORM with NestJS and PostgreSql to load entities via the datasource options object. This object is passed in the useFactory async function within the TypeORM module as shown below: @Module({ imports: [TypeOrmModule.forRootAsy ...

Sending a parameter to a request-promise function within an iteration through a forEach loop

I have successfully implemented an API call for price data. However, I am facing an issue while trying to pass the variable exchange_pair_id into the then() function. Within the forEach loop, the exchange_pair_id is accurate for each asset. But inside the ...

Shifting the MUI DataGrid Pagination table to the left with CustomPagination: A step-by-step guide

Hey everyone, I am currently diving into the MUI data grid to gain a better understanding. In order to meet my design requirements for a table view, I have incorporated the DataGrid component from MUI. For pagination, I am utilizing their custom implementa ...

Image displayed in tooltip when hovering over

I have been experimenting with displaying an image in a tooltip when hovering over it. I came across a fantastic solution that suits my needs: Codepen CSS: @import "compass"; * { box-sizing: border-box; } .tooltip { position: relative; border-bo ...

Having trouble scaling image with CSS, not reacting to size properties

I have little experience in web development, but a small business client has me working on their website while I handle other tasks for them. I've created a home page design that is almost ready to be turned into a template for the chosen CMS. Things ...

Using Node.js to perform a redirect while also setting custom headers

I am attempting to initiate a redirection in an application built with node express, directing it to another application by sending a header in the request. However, when the redirect response occurs, the header is not forwarded to the destination. This i ...

Ways to terminate all websocket connections in a Node.js websocket client prior to restarting the server

Currently, I have set up a websocket client on my Node.js server to listen to a third-party websocket server. The communication between the client and server works fine; however, I am encountering an issue when my server restarts. Every time the server res ...

What's the Reason Behind the Ineffectiveness of Footer Background Color in HTML CSS3?

Having some trouble setting the background color for my footer to something other than white. I've been able to successfully change the background of other layout elements, but the footer is giving me issues. Check out the code below: <footer> ...

Completing a Promise without invoking the 'then' method

As I work on developing a small API for the NPM module Poolio, one common dilemma arises regarding error-first callbacks and promises. The challenge lies in how to cater to both types of asynchronous functions while maintaining consistency in APIs and retu ...

Disable body scrolling on mobile devices in native browsers

When using the native browser on Samsung Galaxy S5 / S6, the following CSS code: body { overflow: hidden; } does not successfully prevent the body from scrolling. Is there a way to work around this issue? Edit: As mentioned below, one workaround is t ...

I'm having trouble persisting my mongoose model data in my MongoDB database

Hey there, I'm new to this and currently attempting to save the Amadeus object I've created into mongosh using the .save() method. However, after connecting to my file through node, editing the Amadeus object, and running amadeus.save(), I check ...

Mongoose aggregate not returning any results

I'm currently working on using Mongoose aggregate to group businesses. I have a MongoDB script that is functioning properly. Below, you'll find the NodeJS code with Mongoose as well as the MongoDB code: History.aggregate() .cursor({ bat ...