Unable to resolve 'C:\absolutepath\MyApp\MyApp\src' in Webpack build process

Hey there, I'm diving into the world of webpack and finding myself in a bit of a pickle trying to troubleshoot an error during the build process. My goal is for the build to run smoothly regardless of my current working directory. I've experimented with various configurations using path, context, __dir, but haven't had any luck so far. Any advice or guidance on this matter would be greatly appreciated!

Just to give you an idea, here's how my project folders are organized:

MyApp-django
├─MyApp
│    ├───src  
│    │     │   index.tsx
│    │     └───components
│    │           └───App.tsx
│    └── static
│           └───frontend
│                   main.js
├─tsconfig.json
└─webpack.config.json

Here's a glimpse at my webpack configuration setup:

const path = require("path");

module.exports = {
  context: path.resolve(__dirname, "MyApp"),
  entry: {
    app: [
      path.join(__dirname, "./MyApp/frontend/src/index.tsx"),
      path.join(__dirname, "./MyApp/frontend/src/components/App.tsx"),
    ],
  },
  mode: "development",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: path.resolve(__dirname, "node_modules"),
      },
    ],
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js", ".jsx"],
  },
  output: {
    filename: "main.js",
    path: path.join(__dirname, "./MyApp/frontend/static/frontend"),
  },
};

This is how my tsconfig file looks like:

{
    "compilerOptions": {
      "noImplicitAny": false,
      "module": "es6",
      "target": "es6",
      "jsx": "react",
      "allowJs": true,
      "moduleResolution": "node",
      "allowSyntheticDefaultImports": true,
      "strictNullChecks": false,
      "sourceMap": true,
      "skipLibCheck": true,
    },
    "include": ["./MyApp/frontend/src/**/*"],
    "exclude": ["node_modules", "**/*.spec.ts"]
    
  }

Lastly, here's the error message that pops up whenever I'm not in the root directory:

Module not found: Error: Can't resolve './src' in 'C:\absolutepath\MyApp-django\MyApp'
resolve './src' in 'C:\absolutepath\MyApp-django\MyApp'
  using description file: C:\absolutepath\MyApp-django\package.json (relative path: ./MyApp)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: C:\absolutepath\MyApp-django\package.json (relative path: ./MyApp/src)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        C:\absolutepath\MyApp\MyApp\src doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        C:\absolutepath\MyApp\MyApp\src.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        C:\absolutepath\MyApp\MyApp\src.json doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        C:\absolutepath\MyApp\MyApp\src.wasm doesn't exist
      as directory
        C:\absolutepath\MyApp\MyApp\src doesn't exist

Answer №1

I discovered a straightforward solution that fits perfectly for me. I decided to leave the config files as they are and created a new script in my package.json. This script allows me to build from the root directory and then return to my original working directory.

// package.json
  "scripts": {
    "dev": "pushd . && webpack && popd"
  }
// terminal
npm run dev

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

Problem encountered when working with several child HTML elements while utilizing Directives in AngularJS

I've been using a template to create a popup menu that displays alerts, and so far it's been working well. However, I wanted to add a manual alert option by including an input text field. But to my surprise, the input field seems to be disabled f ...

How to use Shell command to transfer only HTML files to the designated directory

Currently working on a build script using npm. This build script involves compiling typescript. During the typescript compile process, it copies the folder structure from a ts directory to a dist/js directory. An example of the structure in the ts folde ...

HTML filtering using the <select> element

Is there a way to implement this script for options instead of buttons? The goal is to filter the HTML section, but it seems to not work with <option> tags. Instead of displaying the all class, it shows nothing. CSS .show { display: block; } .filt ...

`Getting smaller screen hides navigation menu - CSS problem`

As I work on developing my website, I have encountered a small issue with the top navigation bar. It functions perfectly at a certain screen resolution, but when I adjust the browser window or view the site on my iPad, the navigation bar disappears. I&apos ...

React encountered an abrupt end of JSON input unexpectedly

As I embark on my coding journey, I am delving into the world of React. However, as I try to create a new app, I encounter an error message stating "unexpected end of JSON input." While installing packages and waiting patiently, the console throws an err ...

Why do I notice POST data when using CURL, but it doesn't show up when I access the .php page through a web browser?

After executing the command below, I receive the POST results in the CLI. However, upon opening , I am unable to see any of the POST data, only other information. I suspect there is something missing or incorrect in my process. Could someone kindly point ...

Delay, Rebootable Delay Functions

I am currently developing a task management application using React. I am working on implementing a feature that will delay the deletion of a checked item by X seconds. If the item is unchecked within that time frame, it should not be removed. The issue I ...

How to adjust the scale in three.js using assignment techniques

Within my threejs project, I am working with two objects that I want to have the same scale vector value. mesh1 = new THREE.Mesh(geometry, material); mesh1.scale.x = 0.47; mesh2 = new THREE.Mesh(geometry, material); mesh2.scale=mesh1.scale; // ...

Exploring AngularJS: A closer look at ngOptions expressions

I have been struggling to populate a Select element with a list of objects for ngOptions. Despite confirming that the data structure is correct and accessible, I cannot get the Select to show the options. Even when rendering the options expression on the p ...

What is the best way to display Json data using ng-repeat in AngularJS?

Is it possible to display JSON data in AngularJS using ng-repeat? I am trying to print only a specific part of the JSON data "data": [{"y":"23","x": "12"}], but nothing appears on the HTML page. Try out the Demo here: http://plnkr.co/edit/zy1C2z39dXuuHDx8 ...

Utilize jQuery to show a specific section of the page based on the hash in the URL

So, the inspiration for this project stemmed from a common issue I encountered: After hitting the register button, the PHP script processes it and displays an error, but the page remains on the login form. Here's the visual representation of the i ...

Enhancing Contentful rich text by removing CSS class when adding a new option

I am integrating contentful into my Next.js project I am facing an issue with the contentful rich text feature where adding a new option causes the CSS class from the first option to be removed and only applies to the second option. I'm perplexed as ...

What could be causing my array/collection/list to not display properly while using the `map()` method for iteration?

I often come across this question, but have never found a suitable duplicate target. Most of the time, there is too much irrelevant code to sift through. In this question, I am attempting to create a simple example that can serve as a duplicate target. He ...

The error message "TypeError: firebase.firestore() is not a function in web JavaScript" indicates

Currently, I am encountering an issue while attempting to upload an image on Firebase Cloud Storage using web Javascript. The error message "firebase.firestore() is not a function" is being displayed in my console. Do you think I might be going about this ...

Leveraging external objects in Vue.js computed functions

Can Vue's computed property be used with an external object? Let's consider the following code example to illustrate the idea: <!-- Vue file --> <template> <div>{{data.auth}}</div> </template> <script> i ...

Display the image before submitting it on Shiny platform

I'm currently developing a Shiny app that enables users to upload images directly to the server. I am wondering if there is a way to display the image on the screen without going through the process of uploading it first and then receiving the rendere ...

Retrieving & Refreshing Data with ajax and Jquery

I have been working on developing a forum system using jQuery, PHP, Bootstrap, and other technologies. The forum allows users to post, delete, and edit their posts. I have implemented an edit button for the author of the post, which triggers a modal wind ...

Using prerender.io in conjunction with native Node.js

Currently, I am working on integrating prerender.io into my Angular 1.6.0 application that is being hosted on a Node.js server. The instructions provided in the documentation for setting up the middleware involve using the connect middleware, with a speci ...

I am interested in embedding several miniature images of solar panels within a polygon shape on Google Maps

[insert image of a polygon here and multiple images of solar panels inside the polygon][1] I need to include multiple small images of solar panels inside a polygon on Google Maps using the @react-google-maps/api package import React from "react" ...

"Implementing a Texture as Material in Three.js: Step-by-Step Guide

I recently discovered Three.js and I'm really enjoying it. As a newcomer to JavaScript, I'm eager to delve deeper into animation and related topics. //UPDATE I've been working on this code snippet, but unfortunately, it's not functioni ...