Webpack is throwing an error stating that it cannot find a module with the relative path specified

Here is the structure of my app (excluding the node_modules directory):

├── actions.js
├── bundle.js
├── components
│   ├── App.js
│   ├── Footer.js
│   ├── Link.js
│   ├── Todo.js
│   └── TodoList.js
├── Containers
│   ├── AddTodo.js
│   ├── FilterLink.js
│   └── VisibleTodoList.js
├── index.html
├── index.js
├── main.js
├── package.json
├── package-lock.json
├── reducers.js
└── webpack.config.js

This is how my webpack config is set up:

module.exports = {
    entry: "./main.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
          {
            test: /\.js$/,
            loader: 'babel-loader',
            query: {
              presets: ['es2015', 'react']
            }
          }
        ]
    }
};

My npm configuration looks like this:

{
  "name": "webpack-redux",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "nothing"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "^3.5.5"
  },
  "dependencies": {
    "react": "^15.6.1",
    "babel-preset-react": "^6.24.1",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2"
  }
}

When running the webpack command, I encounter the following errors:

ERROR in ./components/App.js
Module not found: Error: Can't resolve '../containers/AddTodo' in '/home/oerp/js-programs/redux-test/components'
 @ ./components/App.js 11:15-47
 @ ./index.js
 @ ./main.js

 ERROR in ./components/Footer.js
Module not found: Error: Can't resolve '../containers/FilterLink' in '/home/oerp/js-programs/redux-test/components'
 @ ./components/Footer.js 11:18-53
 @ ./components/App.js
 @ ./index.js
 @ ./main.js

 ERROR in ./components/App.js
Module not found: Error: Can't resolve '../containers/VisibleTodoList' in '/home/oerp/js-programs/redux-test/components'
 @ ./components/App.js 15:23-63
 @ ./index.js
 @ ./main.js
 

The content of my components/App.js file is as follows:

import Footer from './Footer'
 import AddTodo from '../containers/AddTodo'
 import VisibleTodoList from '../containers/VisibleTodoList'

 const App = () => (
   <div>
     <AddTodo />
     <VisibleTodoList />
     <Footer />
   </div>
 )

 export default App

And similarly, for containers/AddTodo.js:

import { connect } from 'react-redux'
 import { addTodo } from '../actions'

 let AddTodo = ({ dispatch }) => {
   let input

   return (
     <div>
       <form
         onSubmit={e => {
           e.preventDefault()
           if (!input.value.trim()) {
             return
           }
           dispatch(addTodo(input.value))
           input.value = ''
         }}
       >
         <input
           ref={node => {
             input = node
           }}
         />
         <button type="submit">
           Add Todo
         </button>
       </form>
     </div>
   )
 }
 AddTodo = connect()(AddTodo)

 export default AddTodo

It seems that there are issues with relative paths containing double dots like ../something.

Is there a specific configuration required for webpack to understand such paths?

Answer №1

According to your file structure, the folder is named Container with a capital C. However, you are attempting to import it as container with a lowercase c. In order for it to work properly, you must either change the import statement or rename the folder because file paths are case-sensitive.

Answer №2

When working with typescript, I encountered an issue where I had forgotten to include the ts and tsx suffixes in the resolve entry.

module.exports = {
  ...
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
  },
};

Adding these suffixes resolved the problem for me.

Answer №3

When including libraries, make sure to specify the exact file path along with its directory relative to the current file. For instance:

import Footer from './Footer/index.jsx'
import AddTodo from '../containers/AddTodo/index.jsx'
import VisibleTodoList from '../containers/VisibleTodoList/index.jsx'

Hopefully, this information proves useful.

Answer №4

To ensure that webpack can successfully resolve the source code, you must include the following code in your webpack.config.js file:

module.exports={
   ...
   resolve:{
      extensions:['.js','.jsx'];
   }
}

Update: An innovative build tool known as "Vite" has emerged to offer a quicker and more efficient development process for contemporary web projects. This plug-and-play tool boasts minimal configuration requirements.

Answer №5

Recently encountered an issue where I had a shared library used across multiple transpiled projects. Initially, I was using symlinks with brunch to facilitate the sharing of resources between these projects. However, upon transitioning to webpack, this setup ceased to function as expected.

To resolve this issue, I found success in tweaking the webpack configuration by disabling symlink resolving.

For example, you can achieve this by adding the following code snippet to your webpack.config.js:

module.exports = {
  //...
  resolve: {
    symlinks: false
  }
};

This solution is well-documented on the official webpack documentation page:

https://webpack.js.org/configuration/resolve/#resolvesymlinks

Answer №6

When utilizing various node_modules directories (such as yarn workspace), it's important to instruct webpack on their locations:

  externals: [nodeExternals({
    modulesDir: path.resolve(__dirname, '../node_modules'),
  }),  nodeExternals()],

Answer №7

After migrating my project to TypeScript, I encountered a problem that was resolved by adding a tsconfig.json file. To fix this issue, I created a new TypeScript project and transferred the tsconfig.json file from the new project to my existing one.

Answer №9

Encountered a similar problem where a module was not found. After some investigation, it was discovered that there was a component

import Gallery from './Gallery/Gallery';
placed at the end of all import statements. Once the placement was adjusted to come after
import React, { Component } from 'react';
, the issue was resolved.

Answer №10

To incorporate it into your configuration, simply include the following line of code. Reference:

externals: [ nodeExternals() ]

Answer №11

When it comes to paths, it's important to pay attention. For instance, the correct way to import a Navbar component is not like this: import Navbar from '@/components/Navbar.vue' but rather like this: ** import Navbar from './components/Navbar.vue'**

Answer №12

My issue was unique in that some of my includes were incorrectly set to 'app/src/xxx/yyy' instead of the correct '../xxx/yyy'

Answer №13

After updating the code from templateUrl: '' to template: '', the issue was resolved.

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

Identifying when two separate browser windows are both open on the same website

Is it possible to detect when a user has my website open in one tab, then opens it in another tab? If so, I want to show a warning on the newly opened tab. Currently, I am implementing a solution where I send a "keep alive" ajax call every second to the s ...

Encountered a 'npm update check failed' error on Windows 10 due to the absence of a .config file

I am currently using Windows 10. Every time I try to run an npm command (version 5.8.0), this error message pops up: npm update check failed Try running with sudo or get access to the local update config store via ...

Using Strapi and Next.js to retrieve user information

After searching for similar questions with no luck, I'm reaching out for help. Building an authentication system using Strapi and Next.js, I'm faced with a task that seems simple but eludes me. The main question is: How can the client retrieve u ...

What's the best way to conceal the navbar while attempting to print the page?

Currently, I am working on developing an application for my school project. One of the features is an invoice sheet with a print option. However, when I try to print by clicking the button or using ctrl+p, the navbar appears in a chaotic and disorganized m ...

AngularJS flexible route parameter

My AngularJS application has routes that can be either: www.website.com/blog/xyz www.website.com/blog/xyz/title/other-params In the second URL, the title parameter is used for readability purposes only and is not mandatory in the URL. Therefore, I have i ...

Having trouble retrieving the innerHTML of a span tag in a JavaScript function

I'm currently working on creating an email message that will have pre-filled text from an asp:Literal when a user clicks a link. The HTML code for this is structured like this: <tr> <td> <img src="../../images/Question.gif" ...

What steps should be taken to ensure that my nodeJS server can maintain the identity of a specific user?

Currently, I am in the process of building a mobile application that utilizes Flutter for the front-end and NodeJS for the back-end. Progress has been steady, but I have hit a roadblock while trying to incorporate a lottery feature. The idea is for the se ...

ensure that only one option can be selected with the checkbox

Can someone help me with applying this code on VueJS? I tried replacing onclick with @click but it's not working for me. I'm new to VueJS, so any guidance would be appreciated! function onlyOne(checkbox) { var checkboxes = document.getElement ...

Viewing HTML web pages using Mozilla Firebox

Printing an HTML table with lots of content has been a challenge for me. Google Chrome didn't work, so I switched to Mozilla Firefox. However, now Firefox is breaking the page inside the table. My question is how can I trigger print preview in Firefox ...

Using the onclick attribute as a unique identifier for a button

I am currently facing a challenge with a form that does not have an ID Here is the code snippet in question: <button class="btn btn-primary" onclick="showModal()" type="button">Browse Data</button> Unfortunately, I don't have any contro ...

Having trouble retrieving the accurate count of buttons with a particular class identifier

I have a task where I need to count the number of buttons within a dynamically created div using JavaScript. The buttons are added from a separate JS file and when I view the code in the browser's inspection tool, everything appears to be correct. How ...

Connecting angular-cli to WebStorm

I am facing an issue with npm where it's not linking the global modules to command line. Angular-cli has been installed as a global module but WebStorm is unable to locate it. Is there a way to instruct WebStorm on where to look for angular-cli? ...

In my React JS class component, I am looking to have the image display switch each time the button is clicked

How can I change the image when clicking a button in a class component? I am familiar with function components, but unsure how to achieve this. class CoffeeImages extends React.Component{ constructor(props){ super(props) ...

Function returning undefined when accessing prototype property in JavaScript

When attempting to create an image rotator using prototypal inheritance, I am encountering an error in the console showing: TypeError: this.curPhoto is undefined this.curPhoto.removeClass('previous'); I have placed this code in the callb ...

I encountered a ReferenceError stating that the variable "req" is not defined when I try to

I am currently developing a login application using React.js and Node.js (Express, JWT), but I am facing an issue when trying to export my function. I keep receiving the error ReferenceError: req is not defined, even though I have defined req. How can I re ...

Discovering methods to store browser credentials securely in jQuery

I need to prevent the login button from being enabled when either the username or password fields are empty. Check out the code snippet below: $(document).ready(function(){ $('input').on('keyup blur mouseenter', function(e) { ...

Deploying the npm package artillery for seamless integration

Every time I attempt to execute sudo npm install -g artillery, an error is triggered as shown below: npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fe93979097939f8a9d96beced0cdd0ce">[email protecte ...

Tips for utilizing the vuetify readonly prop while enabling the selection menu

In my project, I have a grid containing v-autocomplete components with the multiple attribute. To maintain clean formatting, I decided to show only a shortened version of the content using the selection slot feature provided below: <v-autocomp ...

Dynamic content with Socket.io in Node.js

I am attempting to create a scenario where nodejs triggers an event in an irc chat that causes a html page (Running on *:3000) to execute some JavaScript. However, I am facing an issue where the showDiv(); function is not being executed as expected. Curre ...

The functionality of Bootstrap Tabs is compromised when used within a jQuery-UI dialog window

My goal is to develop a user interface similar to MDI for my application. To achieve this, I am utilizing the dialog feature of the jQuery UI library. To dynamically create a dialog window on demand, I have coded a helper function as shown below: functio ...