"Encountering silence in the console when inspecting elements on Chrome (during Webpack

Hey there, I'm having trouble viewing output in my Chrome inspect element. Here are the files I am working with:

Output

Webpack.config.js

const path = require("path");

    module.exports = {
      entry: ["./src/js/index.js"],
      output: {
        path: path.resolve(__dirname, "dist/js"),
        filename: "bundle.js"
      }
    };

PACKAGE JSON

{
  "name": "forkify",
  "version": "1.0.0",
  "description": "forkify project",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "author": "Gaurav Yadav guided by Jonas",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10"
  }
}

TEST.JS

 console.log("Export data");
    export default 23;

INDEX.JS

// Global app controller
import num from "./test";
console.log(`${num} from test`);

dist/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>test</title>
  </head>
  <body>
    <script>
      src = "js/bundle.js";
    </script>
  </body>
</html>

The folder for my project is named FORKIFY. It contains three subfolders: dist, src , nodemodules, and also has three files: pacakage-lock.json, pacakage.json, webpack.config.js. See directory image here. Could you help me figure out why my console is empty? I was following this video tutorial to write my code.

Link to Video Tutorial

Can you point out where the problem might be occurring and which file may need adjustments? Do I need to make changes in my webpack config file?

Answer №1

Your folder arrangement needs adjustment.

const path = require("path");

    module.exports = {
      entry: ["./src/js/index.js"],
      output: {
        path: path.resolve(__dirname, "dist/js"),
        filename: "bundle.js"
      }
    };

The dist directory will be generated when the webpack command is executed, and you have specified that your index.html file should be in the dist folder.

Please place your index.html file at the main level of your project. If the js folder is located inside the dist directory, include a forward slash to indicate it as a separate directory e.g.

path: path.resolve(__dirname, "dist/js/")

Recommended Folder Structure

node_modules
src
 -js
  - index.js
index.html
package.json
webpack.config.js

// webpack.config.js

const path = require('path');

module.exports = {
    entry: './src/js/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist/js/')
    },
    watch: true
}

// index.js

console.log('logging');

// index.html

<h1>WebPack works!!</h1>
<script src="dist/js/bundle.js"></script>

Execute the command webpack, this will generate the bundle.js file within the dist/js/ folder and then automatically open your index.html file in the browser for viewing.

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

The functionality of the JQuery $.post method may be compatible with Firefox but may encounter issues when

I've encountered an issue with my website where certain functions that update the database using $.post work perfectly in Firefox, but fail to function properly in Internet Explorer. I'm struggling to identify the root cause of this problem. Here ...

In unique circumstances, text remains unbroken

I'm facing an issue where text doesn't break in a popup created with Vue.js and included in the header section. Oddly enough, the text breaks properly when the popup is included in the main screen, but not in the header. I even added a border aro ...

Guide on submitting a form in ReactJS with Material UI Dialog

I utilized the Material UI Dialog to create a form list. In the official example: <Dialog title="Dialog With Custom Width" actions={actions} modal={true} open={this.state.open} > This dialog ...

Exploring the functionalities of JavaScript methods and nested components within Vue.js

Learning Vue.js has been an interesting experience for me. However, I am facing challenges with methods and child elements in the library. It seems like there is something simple that I am overlooking. In my current project, I have list items rendered on ...

Record information in the database once the order has been placed

Can anyone help me troubleshoot my code? I am having issues with placing an order and saving it to the database. I am using ajax/jquery, and even though it reaches the success function, it does not save in the database. PS: I have also included place_orde ...

Angular (version 2.4.5) is throwing an error stating that you cannot bind to the 'ngTemplateOutletContext' property because it is not recognized as a valid property of the 'ng-container' component

While I understand that there have been similar questions regarding errors during the migration from Angular 4 to 5, my issue pertains to building an Angular 2.4.5 project with webpack. Despite successful compilation without errors, attempting to run the p ...

What is the best way to sort a combination of numbers and text strings?

Within my table, I have column names enclosed in <th> tags and only numerical values inside <td> tags. When the user clicks on a <th> tag, the sorting algorithm organizes the values in ascending or descending order. .sortElements(function ...

Is it possible to create a horizontal navigation bar with buttons that scrolls when media queries are activated? I am looking for a solution using HTML,CSS, JavaScript, and Bootstrap

Struggling to create a horizontally scrollable navigation with buttons for media queries in Bootstrap 5.2, using SCSS for styling. This project is starting to feel overwhelming as we try to replicate the EA site. We're aiming to mimic the behavior of ...

Position the <a> to the right side of the div

Is there a way to right-align the <a> element, which contains a Button with the text Push Me, within the <div> (<Paper>)? https://codesandbox.io/s/eager-noyce-j356qe This scenario is found in the demo.tsx file. Keep in mind that using ...

What is the best way to transform an Observable array containing objects into an Observable that emits the data contained within those objects?

Encountering an error: Error: Type 'Observable<Country[]>' is not assignable to type 'Observable'. Type 'Country[]' is missing properties like name, tld, alpha2Code, alpha3Code and more.ts(2322 The issue might be due ...

The app is opening the index.html file instead of the expected index.jsx file

After creating a page with React.jsx, I encountered an issue where my page was initially opening index.jsx upon running npm start. However, when I deleted and then restored the index.html file to "public", the page started opening index.html instead. This ...

Utilize Javascript to pull information from a REST API and generate a dynamic table with the retrieved

Generating a table from JSON data obtained from a REST API without utilizing Angular poses a challenge in a specific application. My query is: Is it necessary to use var table = document.createElement("TABLE"); within the script to construct the entire ta ...

JS Month Interval Bug Causing Issues with Chart Date

This script retrieves and summarizes download data from MySQL by day, displaying it as a chart. However, there's an issue with the way dates are handled between PHP and JavaScript (Highcharts). While PHP outputs month values from 1 to 12, JavaScript c ...

show information in a continuous manner using javascript

I'm having trouble extracting the latitude and longitude coordinates of markers to display them on the map. Even though my parser.php file successfully retrieves data from the database, I am struggling to format it into JavaScript. Any suggestions? & ...

Issue encountered while attempting to load several google charts simultaneously

What do I need? I am in need of two Google charts, one on each tab of the website as shown in the screenshot below: Tabs What seems to be the issue? The second chart is not loading properly and showing mixed information. This can be observed in the scre ...

Delete any HTML content dynamically appended by AJAX requests

I'm currently working on a page dedicated to building orders, where the functionality is fully dependent on ajax for finding products and adding them dynamically. However, I encountered an issue when attempting to remove an item that was added via aj ...

Issue: Bootstrap's JavaScript is dependent on jQuery; Browserify and Laravel Elixir are also required

Having some trouble loading bootstrap.js with browserify and Laravel elixir. I've used npm to install the necessary packages, but upon trying to load my page, I keep getting an error message that says "Error: Bootstrap's JavaScript requires jQuer ...

NPM: Handling multiple prehooks with the same name

Is it possible to have multiple prehooks with the same name in my package.json file? For example, having two instances of pretest: "scripts": { "start": "react-scripts start", ... "pretest": "eslin ...

Struggling with transferring form input data to a different file using JavaScript, Node.js, React.js, and Next.js

I've been struggling with writing form input to a separate file in JavaScript. I created a demo repo to showcase the issue I'm facing. Check it out here: https://github.com/projectmikey/projectmikey-cant-write-to-api-dir-stackoverflow Locally, t ...

Platform Independent Data Storage Solution

Looking to create a Cross-browser compatible Web Application using HTML, JS, and CSS. In need of a robust database storage solution that can be queried on the client side using JS. While Web SQL/SQLite seems like a good option, it lacks support in IE. Does ...