Encountering issues with compiling files in react app using webpack, failing to compile as anticipated

When it comes to compiling, I prefer using webpack with TypeScript files.

In my webpack.config.js file:

module.exports = async (env, options) => {
  const dev = options.mode === "development";
  const config = {
    //Webpack configuration properties
  };

  return config;
};

After running 'npm run server', I encountered the following issue:

ERROR in Error: Child compilation failed: Module not found: Error: Can't resolve '../loginfile.js' in '/Users/username/summarizr2/summarizr/src/login'
ModuleNotFoundError: Module not found: Error: Can't resolve '../loginfile.js' in '/Users/username/summarizr2/summarizr/src/login'

A similar problem also occurs with the logoutfile. In an HTML file, I have the following code:

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

    <!-- Office JavaScript API -->
    <script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>

    <script type="text/javascript" src="../loginfile.js"></script>
</head>

I've attempted variations such as

<script type="text/javascript" src="./loginfile.js"></script>
and src="loginfile.ts"

The project structure is as follows:

 ├ src
 │  ├ commands
 │  │  ├ commands.html
 │  │  ├ commands.ts
 │  ├ constants
 │  │  ├ authentication.ts
 │  ├ login
 │  │  ├ loginfile.html
 │  │  ├ loginfile.ts
 │  ├ logout
 │  │  ├ logoutfile.html
 │  │  ├ logoutfile.ts
 │  ├ services
 │  │  ├ commands
 │  │  ├ common
 │  ├ taskpane
 │  │  ├ components
 │  │  ├ endlogout.html
 │  │  ├ index.css
 │  │  ├ index.tsx
 │  │  ├ login.html
 │  │  ├ logoutcomplete
 │  │  ├ taskpane.html
 │  │  ├ urls.ts
 ├ tailwind.config.js
 ├ tsconfig.json
 └ webpack.config.js

What could be causing this issue?

To simplify, let's consider a scenario where I have a test.ts file and test.html file located in src/test folder. The test.html file contains:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

    <script type="text/javascript" defer src="test.js"></script>
</head>

<body>

</body>

</html>

An error message such as the one below is displayed:

  • ModuleNotFoundError: Module not found: Error: Can't resolve './test.js' in '/Users/*****/****/summarizr2/summarizr/src/test'

In my understanding, the test.js file should be located in the dist folder.

Answer №1

Your question seems to have some ambiguity regarding whether the HTML code you provided is the template or the actual output HTML as seen in the dist folder or in the DOM. Based on the assumption that it is the actual template content, here is a response.

The purpose of the html-webpack-plugin is to enable Webpack to automatically generate the HTML, including the necessary <script> tags that point to your JavaScript chunk files. It appears that in your template file, you are attempting to manually create the <script> tag for loading the chunk.

If no custom template is specified, the HtmlWebpackPlugin will create a basic HTML file with the required script tags injected automatically.

However, since you seem to require a custom template in order to include an additional script tag that Webpack is not aware of, you should utilize the template feature. In this template, you can add your extra Office for JS script without including any script tag for the chunk. The HtmlWebpackPlugin will handle injecting the necessary script tags in the final HTML files located within the dist directory and those served by the development server.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />

    <!-- Include Office JavaScript API -->
    <script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>

</head>
<body>
   
    <!-- Webpack Scripts will be automatically injected here -->
</body>
</html>

Answer №2

Your login script is utilizing a JavaScript module

<script type="module" src="../loginfile.js"></script>

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

Struggling to get JavaScript to successfully load a .txt file in order to load various links

I created a cool feature that takes users to a random link, but I currently have a large list of links and wanted to find a way for JavaScript to read them from a text file. The code I have tried so far is not working, and I have experimented with other s ...

"Critical issue: Meta tags are not present on the dynamic pages of the NextJS

In my NextJS application, the pages are structured as follows: App --pages ----_app.js ----index.js ----company.js ----users ------[userID].js I have a dynamic page named [userID].js that retrieves the userID through the router to display information for ...

How can you make sure that VS Code always utilizes relative paths for auto imports in TypeScript?

VS Code has been automatically importing everything using Node-like non-relative paths relative to baseUrl, which is not the desired behavior. Is there a way to instruct VS Code to import everything with relative paths, excluding Node modules? Removing t ...

How come TypeScript tuples support the array.push method?

In the TypeScript code snippet below, I have specified the role to be of Tuple type, meaning only 2 values of a specified type should be allowed in the role array. Despite this, I am still able to push a new item into the array. Why is the TS compiler not ...

What is the process for implementing an image as the background instead of a color for each column in a Google chart?

I'm currently working with Google Chart and I have set up a column chart. However, I am looking to display a background image instead of a background color in each column. Is this achievable with Google Chart? If so, how can I accomplish this? If anyo ...

Retrieve the visitor's IP address following the submission of an AJAX form

Currently, I am facing an issue with my HTML form and JavaScript method integration. Whenever a visitor submits the form, a JavaScript method is triggered which sends an AJAX request to a PHP file on my server. The problem arises when trying to retrieve ...

NestJS RabbitMQ Microservice Integration

Currently, I am attempting to establish a connection to a Rabbit MQ docker container through NestJS microservice. The setup involves running it using vagrant. Unfortunately, I keep encountering the following error: [1601171008162] ERROR (32761 on local): D ...

Exploring the seamless integration of Next.js, TypeScript, and useContext across

Revision: I realized that I had forgotten to include the following line of code in my Header.tsx component: import Link from 'next/link'; After rectifying this oversight, everything started functioning properly. I am currently struggling with ...

Is using setTimeout in a group of promises blocking in JavaScript?

Is it possible for multiple requests to be queued up and executed in sequence when calling the function func? The third promise within func includes a lengthy setTimeout that can run for as long as 3 days. Will additional calls to func trigger one after an ...

Finding repeating elements in an array of objects

Is there a way to identify duplicates in an array based on type, name, and size, increment the amount, and then remove the duplicate entries? [ { "name": "Pizza with pepper", "imageUrl": "...", ...

Issue with making requests across origins in Vuejs using axios

Currently, I am utilizing Vuejs and axios for handling web requests. So far, I have successfully managed to perform GET, POST, and PUT operations. However, the new challenge that I am facing is uploading media to the server. The server necessitates sending ...

Refreshing the page causes the Angular/Ionic Singleton instance to be destroyed

I have a TypeScript singleton class that is responsible for storing the login credentials of a user. When I set these credentials on the login page and navigate to the next page using Angular Router.navigate (without passing any parameters), everything wor ...

What steps can I take to make my search button work with this JavaScript code?

I am struggling with integrating my custom search bar with a JavaScript code to make it functional. Here is the code snippet for the Search Button: document.getElementById('searchform').onsubmit = function() { window.location = 'http:/ ...

Guide to creating scroll-based animations for a Div element

I've been brainstorming ways to rotate a div as I scroll. My goal is to recreate the effect shown in this codepen. However, I'm struggling to implement scrolling functionality. What I envision is scrolling down causing the word Data to rotate in ...

What is the best way to arrange cards in a specific order with breaks in between each flip

I am currently working on creating flip cards using HTML and CSS. I have successfully implemented the hover effect which flips the cards when hovered over. Now, my goal is to make the cards automatically flip one after the other at specific time intervals ...

Can a ng-repeat value be assigned to a text input field?

<tr ng-repeat="person in users" ng-class="{'chosen': person.AdmissionID == currentSelection}" ng-click="selectRow(person.AdmissionID)"> <td>{{person.AdmissionID}}</td> <td>{{person.AdmissionNumber}}</td> ...

The initial character of the input must always be a letter

I need assistance with an input element that requires 5 characters, with the first character being a letter: <input mdInput #acronyme placeholder="Company" type="text" maxlength="5" minlength="5" required [value]="acronyme.value.toUpperCase()"> Th ...

What is the best way to indicate progress as the canvas resizes an image?

Is there a way for me to access progress updates? My main focus is on receiving progress information, regardless of how it will be displayed. I may choose to use a progress bar in the future, but my current inquiry pertains solely to obtaining the data it ...

Retrieve a formatted item from a JSON document

Within my Next.js project, I have implemented a method for loading translations and passing them into the component. Here is an example: import "server-only"; import i18nConfig from "../../i18n-config"; const dictionaries = { en: () ...

Guide to creating a nested list using the jQuery :header selector

Here is the structure of my html: <h1 id="header1">H1</h1> <p>Lorem ipsum</p> <h2 id="header2">H2</h2> <p>lorem ipsum</p> <h2 id="header3">H2</h2> <p>lorem upsum</p ...