webpack is having trouble locating the src file, even though it should not be searching for it in the first place

I'm currently delving into the world of using TypeScript with React and am following a helpful tutorial at: https://blog.logrocket.com/how-why-a-guide-to-using-typescript-with-react-fffb76c61614

However, when attempting to run the webpack command through the npm script "pile" defined in my package.json, I encounter the error message:

ERROR in Entry module not found: Error: Can't resolve './src' in '/my/home/directory/projects/tsx-tutorial'

Below is the directory structure of my project:

tsx-tutorial
├── app.tsx {<---- Is this supposed to be my entry point?}
├── dist
├── index.html
├── index.ts
├── lookTree.txt
├── node_modules.zip
├── package-lock.json
├── package.json
├── src {<----- Ah, there it is??}
│   └── hello.ts
├── tsconfig.json
└── webpack.config.js

2 directories, 10 files

Here's my webpack.config.js:

var path = require("path");
var config = {
  entry: "app.tsx", // Why isn't there anything referring to ./src here?
  output: {
    path: path.resolve(__dirname, "build"),
    filename: "bundle.js"
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js"]
  },
  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader",
        exclude: /node_modules/
      }
    ]
  }
};

I've made sure to not request any files from 'src', so why is it looking there? It feels like I'm overlooking something quite fundamental.

Lastly, here's my package.json:

{
  "name": "tsx-tutorial",
  "version": "0.0.1",
  "description": "to help me learn tsx-fu",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "pile": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "ts-loader": "^4.4.1",
    "webpack": "^4.12.1",
    "webpack-cli": "^3.0.8"
  },
  "dependencies": {
    "@types/react": "^16.4.1",
    "@types/react-dom": "^16.0.6",
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  }
}

Your assistance in helping me navigate through these issues is greatly appreciated! Thank you for guiding a beginner like myself.

Answer №1

Even though it may seem like you have configured the file correctly, in order for webpack to recognize it, the configuration must be exported at the end of the file.

module.exports = config

To clarify the issue: starting from version 4, webpack automatically uses ./src as the entry point if no specific configuration is provided. ./src behaves similarly to ./src/index.js based on how module resolution functions, but keep in mind that the filename and extension can be customized.

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

How can I activate an npm task as a post-install hook using npm install?

Once the command npm install has been executed, my intention is to then run npm run jspm install I possess a package.json file "scripts": { "postinstall" : "npm run jspm install", "jspm": "jspm" }, An issue arises where npm run jspm install is ...

Does a <Navigate> exist in the react-router-dom library?

Within the parent component import LoginPage from "pages/admin"; export function Home() { return <LoginPage />; } Inside the child component import { useRouter } from "next/router"; export default function LoginPage() { co ...

Using TypeScript's conditional types for assigning types in React

I'm tasked with creating a component that can belong to two different types. Let's call them Type A = { a: SomeCustomType } Type B = { b: SomeOtherDifferentType } Based on my understanding, I can define the type of this component as function C ...

What is the best way to combine two calls into a single condition check in React using Typescript?

Does anyone have suggestions on how to tackle this issue? I'm encountering difficulty as it is contained within a tag, which means it adheres to specific rules that I am unfamiliar with. The task involves generating a graph, and when the expandGraph v ...

Execute a selector on child elements using cheerio

I am struggling to apply selectors to elements in cheerio (version 1.0.0-rc.3). Attempting to use find() results in an error. const xmlText = ` <table> <tr><td>Foo</td><td/></tr> <tr><td>1,2,3</td> ...

Encountered a hiccup during the deployment of an Angular application on Heroku

I've been working on deploying an Angular app called "test-app" to Heroku via GitHub and everything seems to be going smoothly, except for setting up the express routing function. I've tried different paths, but Heroku keeps throwing this error: ...

Issues arise with Jest tests following the implementation of the 'csv-parse/sync' library

Currently utilizing NestJs with Nx.dev for a monorepo setup. However, I've come across an issue after installing csv-parse/sync - my Jest tests are now failing to work. Jest encountered an unexpected token Jest failed to parse a file due to non-stand ...

Every time I try to npm run dev, I encounter an issue: module "postcss/lib/parser" cannot be found

While using Next.js, I encountered an issue when running the script "npm run dev". The error message states that it cannot find a module at a specific path within the postcss folder. However, upon checking the directory, I found that the required file &apo ...

Identifying memory leaks caused by rxjs in Angular applications

Is there a specific tool or technique available to identify observables and subscriptions that have been left behind or are still active? I recently encountered a significant memory leak caused by components not being unsubscribed properly. I came across ...

Obtain abbreviated names for the days of the week starting from Monday to Sunday using JavaScript

Is there a way to retrieve the abbreviated names of each day of the week in JavaScript, starting from Monday through Sunday? ...

The BehaviorSubject will consistently emit identical values to each subscription

I am currently facing an issue with the BehaviorSubject where it emits a value for every subscription. This means that if I have, for example, 2 subscriptions to this.projectService.projectState$ streams using methods like async or tap, the projectState$ e ...

Holding an element in TypeScript Angular2 proved to be challenging due to an error encountered during the process

I attempted to access a div element in my HTML using ElementRef, document, and $('#ID') but unfortunately, it did not work. I tried implementing this in ngOnInit, ngAfterViewInit, and even in my constructor. Another method I tried was using @Vie ...

The user authentication service indicates that no user is currently logged in

Currently, I am working on implementing a route guard to distinguish between authenticated users and guests. In order to achieve this, I have created an auth-guard service along with an auth service. Although the user data is successfully stored in the loc ...

The Vite localhost server cannot be accessed through the web browser

I recently integrated Vite into my Laravel project, but I'm facing an issue when running 'npm dev' as it shows a message saying 'this site can't be reached'. Surprisingly, another project of mine is experiencing the same probl ...

When using Node.js, you may encounter the error message: "TypeError: brevo.ApiClient is not a constructor

My goal is to set up an automatic email sending system that, upon receiving details like name and email, will send a confirmation email to the provided email address with the message "subscribed." I've been working on this task for about 7 hours strai ...

Describing the implementation of UNO out parameters within definitions

The UNO API offers support for inout and out parameters. In this scenario, a variable is passed into a function, the function modifies the variable, and the updated value of the variable can be accessed outside the function. Javascript lacks native suppor ...

Gathering adorned categorizations (sans any listed category divisions)

My current setup involves an event dispatcher class that triggers listeners on specified occurrences. I've successfully implemented registering event listeners via decorators, but I feel like there may be a better solution out there. At the moment, e ...

Generating a dynamic table using Angular

My goal is to populate a table dynamically using the code below: teams.component.ts import { Component, OnInit } from '@angular/core'; import { first } from 'rxjs/operators'; import { TeamService } from 'src/app/services/team.ser ...

What is the best way to send props to a child component in JSX with TypeScript?

While passing props to the child, I encountered an error message stating "Property 'isClicked' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes". I defined "isClicked?: boolean" in my code. What additional steps sho ...

Vue-Head

I am currently attempting to update the social sharing meta tags on my website with data fetched from the backend database using an API call. head: { // In order to utilize "this" in the component, it is necessary to return the object within a function t ...