Error: Unable to locate script file with npm installation of AngularJS

After installing Angular using npm, I added the following script to my public/index.html file:

<script src="/node_modules/angular/angular.js"></script>

However, I am encountering a 404 error in the Chrome console. Does anyone have any suggestions on how to properly include the script?

Answer №1

Your node_modules directory is most likely not accessible to the public.

There are several ways to address this issue, such as:

  • Compiling your angular library with your code into a single script file, for example using webpack,
  • Placing the angular.js file in the public folder alongside your index.html and linking to it from there, and
  • Downloading the angular library from a CDN, for instance:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    

The most appropriate solution depends largely on your specific scenario.

Answer №2

My suggestion is to utilize a content delivery network (CDN) for loading AngularJS in your project:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>

Further recommended reading: Benefits of Using a Content Delivery Network (CDN)

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

What is the best way to retrieve router parameters within a JSX component?

How can I pass the post ID as a prop to the EditPost component in order to edit it? render() { return ( <Router> <Switch > <Route path="/edit/:id"> <EditPost index={/*what do I do here?*/} /> ...

Guide for Sending a Textnode from One Page to a Different Page within a Specific Id Element through PHP

firstpage.html : <body> <?php $text = $_POST['text']; ?> <p style = "color:red; " id = "getext"><?php echo $text; ?></p> </body> secondpage.php : <body> <?php $text = $_POST['text']; ?> ...

Designing an Angular ui-router feature: Implementing a dynamic navbar that seamlessly integrates into all primary states as well as their sub-states

I am facing a challenge with my website's navbar. I want it to be displayed on most pages, but not all of them. I tried using ui-view to load it only for specific pages, but I have hit a roadblock. My goal is to connect the navbar to main states such ...

Is it possible to make a call to an endpoint from within the node project?

I'm currently working on a MERN app that dynamically adds meta tags to React pages without using server-side rendering. In order to achieve this, I need to extract the query parameters from the main server file and assign the relevant metadata content ...

The scrollIntoView feature of JavaScript is unable to scroll an element to the exact top of the scrolling

Vue is the framework I am utilizing for my current project. JavaScript: let captureElement = document.getElementById('tag' + (index - 1)); if (captureElement) { captureElement.parentNode.scrollIntoView({behavior:"smooth",block: "start", inl ...

Chrome has a malfunction with the SVG 'use' tag

Within the SAP platform, I have a navigation system built with AngularJS and Angular Route that utilizes icon-based navigation through svg-sprite. Here is an example of my inline code: <div style="height: 0; width: 0; position: absolute; visibility: hi ...

How to automatically refresh a page in AngularJS after a POST request

After making a POST request, I attempted to use $state.reload in my controller to refresh the page. However, it is not updating the data on my page after registering the form. I have to manually refresh the page to see the correct data. .controller(' ...

Errors occur when attempting to install plugins from npm

I am currently coding in Visual Studio 2017 using Ionic v2 to develop an app for beacon scanning. However, every time I try to install a plugin, I encounter errors from npm about the versions of node and npm being incompatible. Here are my current versions ...

Implement the use of HTML buttons to dynamically change the source attribute of an image using

I am in the process of creating a webpage with 25 different images that will be displayed one at a time. Each image represents unique combinations from two sets of items: (ant, blueberry, ladybug, marshmallow, mushroom) and (blimp, truck, moon, ocean, redw ...

Limiting the input in a text box to only allow whole numbers and no decimal values

What is the best way to limit a textbox to only accept whole numbers and exclude decimal values and alphabets? ...

Is there a way to print an HTML page in Landscape mode within my Vue.js project?

I have been able to successfully print an HTML page in Landscape mode using the code below. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,maximum-scale=1.0"> ...

Press the "Reveal More" button to expand the content to its full size

I am currently working on coding a "read more" section using a button. I have looked at some existing solutions, but none of them are to my liking. My plan is to create a div that includes all the relevant content. My goal is to have a div at the bottom w ...

Hiding both clear buttons in the MUI Autocomplete component on Chromium: A simple guide

The issue with the clear button is specific to Chromium; it does not appear in Firefox. Take a look at an example of a MUI React Autocomplete component displaying two clear buttons. Various solutions mentioned in this thread only hide the rightmost butto ...

Avoid reloading the page when submitting a form using @using Html.BeginForm in ASP.NET MVC

I have a webpage featuring a model that needs to be sent to the controller along with additional files that are not part of the model. I have been able to successfully submit everything, but since this is being done in a partial view, I would like to send ...

Identifying a user's unique identity through a POST request using Node.js

Currently, I am developing a browser game that integrates voice communication. To capture audio within the browser, I have chosen to use wami-recorder. This tool relies on Flash technology to make a POST request to the server containing the recorded audio. ...

Tips for obtaining a binary file sent through an HTTP:POST request using angular.js

I'm currently working on a project that involves using an Angular.js based viewer with a custom server. My goal is to implement an "execute & download" button. To send the request for execution, I am using an HTTP:POST method with specific headers: ...

When attempting to pass react-intl as an argument in a method of a React component during Jest testing, an error is thrown stating, "TypeError: intl.formatMessage is not a function."

Currently, I am in the process of unit testing my React component using Jest. Within this component, there are several methods that are called upon. As an example: export function fetchText(text, intl) => ((text !== 'NA') ? (intl.formatM ...

Having trouble assigning a value to ng-model following a mathematical operation

Currently, I am in the process of developing a filter that allows users to choose a property location based on specific parameters. The filter will allow users to select multiple criteria, and from there, I will perform arithmetic calculations to determine ...

Hover over the sprites using the "spritely" plugin to see the magic unfold

I'm looking to initiate an animation when the mouse hovers over a sprite and have it stop when the mouse moves away. After exploring various solutions, I found one that seemed promising: Why does jQuery spritely animation play an extra frame on secon ...

Fixing issues with Ajax calls in Internet Explorer versions 7 and 8

Here is the Javascript code I have written: $("#login").click(function(){ username=$("#user_name").val(); password=$("#password").val(); $.ajax({ type: "POST", url: "login.php", data: "username="+username+"&passw ...