Issue with deploying lodash library

I'm encountering an issue with lodash. Whenever I deploy using gulp, I consistently receive the following error:

vendors.min.js:3 GET http://127.0.0.1/projects/myproject/lodash 404 (Not Found)

I have declared the library in my index.html file

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

I import lodash into my typescript file

///<reference path="../../../typings/modules/lodash/index.d.ts" />
import * as _ from "lodash";

Everything works fine when I test my website locally (by launching lite server with npm start).

Now, I am trying to deploy my website using Gulp. Here is my gulp file:

gulp.task('app-bundle', function () {
  var tsProject = ts.createProject('tsconfig.json', {
      typescript: require('typescript'),
      outFile: 'app.js'
  });

  var tsResult = gulp.src([
    'node_modules/angular2/typings/browser.d.ts',
    'typings/main/ambient/firebase/firebase.d.ts',
    'app/**/*.ts'
  ])
    .pipe(ts(tsProject));

  return tsResult.js.pipe(addsrc.append('config-prod.js'))
                    .pipe(concat('app.min.js'))
                    .pipe(uglify())
                    .pipe(gulp.dest('./dist'));
});

gulp.task('vendor-bundle', function() {
    gulp.src([
            'node_modules/es6-shim/es6-shim.min.js',
            'node_modules/systemjs/dist/syst...
                   
gulp.task('default',[ 'app-bundle', 'vendor-bundle' ], function() {
  gulp.src('index.html')
    .pipe(htmlreplace({
        'vendor': 'vendors.min.js',
        'app': 'app.min.js'
    }))
    .pipe(gulp.dest('dist'));
});

When I test my website, I encounter the following errors:

    vendors.min.js:3 GET http://127.0.0.1/projects/myproject/lodash 404 (Not Found)r @ vendors.min.js:3e.scheduleTask @ ve...

    vendors.min.js:3 Error: XHR error (404 Not Found) loading http://127.0.0.1/projects/myproject/lodash
    Error loading http://127.0.0.1/projects/myproject/lodash as "lodash" from ht...
    
Here is my SystemJS : 

System.config({
 paths: {
   'rxjs/add/observable/*' : 'node_modules/rxjs/add/observable/*.js',
   'rxjs/add/operator/*' : 'node_modules/rxjs/add/operator/*.js',
   'rxjs/*' : 'node_modules/rxjs/*.js'
 },
 map: {
   '@angular' : 'angular2',
   'videogular2' : 'node_modules/videogular2',
   'rxjs': 'node_modules/rxjs',
   'lodash': 'node_modules/lodash'
 },
 packages: {
   map: {
     'rxjs': 'node_modules/rxjs'
   },

   lodash:{
     main:'lodash',
     defaultExtension:'js'
   }
 });
 System.import('app/boot')
       .then(null, console.error.bind(console));
 });

<p>I have been searching for a solution for many days and would greatly appreciate any assistance.</p>

<p>When deploying, I also add this script:</p>

<pre><code>document.addEventListener('DOMContentLoaded', function () {
  System.import('boot')
        .then(null, console.error.bind(console));
});

Answer №1

At last, I achieved success!

  1. Establish a System configuration as follows :
System.config({
    meta:{
        'vendors.min.js':{
            format:'global'
        }
    },
    map:{
        'lodash':'http://127.0.0.1/js/lodash.min.js'
    }
});
  1. Create a gulp task for lodash
gulp.task('lodash', function(){
    return gulp.src('node_modules/lodash/lodash.min.js')
        .pipe(gulp.dest('./dist/js'));
});

Hopefully, this solution will be beneficial to others.

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

Creating a web application using Aframe and NextJs with typescript without the use of tags

I'm still trying to wrap my head around Aframe. I managed to load it, but I'm having trouble using the tags I want, such as and I can't figure out how to load a model with an Entity or make it animate. Something must be off in my approach. ...

Tips for setting up a websocket connection between angular-socketio and flask-socketio

As a newcomer to web sockets, I am currently working on implementing a web socket server using flask-socketio for the server and angular-socketio for the client-side. For the server side in Flask, this is the code snippet I am using: application.py @ ...

Using variables to replace 'placeholders' in Typescript with string interpolation

Seeking a definitive answer on this matter, I pose the question: In C#, an example of which would be as follows: var text = "blah blah"; var strTest = String.Format("This is a {0}", text); //output: 'This is a blah blah' How can I accomplish t ...

What is the best method to publish my npm package so that it can be easily accessed through JSDelivr by users?

I've been working on creating an NPM package in TypeScript for educational purposes. I have set up my parcel configuration to export both an ESM build and a CJS build. After publishing it on npm, I have successfully installed and used it in both ESM-m ...

The element 'router-outlet' in Angular 9.0 is not recognized within a lazily loaded module

My attempt at adding a new lazyloaded module to the app component is running into an issue. When I try to include child routes for the new module, an error stating that 'router-outlet' is not a known element:in lazy loaded module is thrown. In t ...

What are the two different ways to declare a property?

I am trying to update my interface as shown below interface Student{ Name: String; age: Number; } However, instead of the current structure, I would like it to be like this interface Student{ Name: String; age | DOB: Number | Date; } This means t ...

Analyzing feedback according to the ResponseHeaders

When sending a request to a REST API using http.get(), the response headers usually contain metadata related to page number, total results, and page count. Angular's HttpClient handles parsing and returning data from the response.body in an Observabl ...

Creating a new Angular2 component for a separate URL path

In my scenario, I have a PageComponent that gets refreshed with new data when the URL changes (using PageService). It currently utilizes the same PageComponent object, but I am looking to make it a new object when the URL changes. 1st Question: How can ...

Angular and Jest combo has encountered an issue resolving all parameters for the AppComponent. What could be causing this error?

I am currently working within a Typescript Monorepo and I wish to integrate an Angular 8 frontend along with Jest testing into the Monorepo. However, I am facing some challenges. The tools I am using are: Angular CLI: 8.3.5 My Approach I plan to use ...

Issue with comparing strings in Typescript

This particular issue is causing my Angular application to malfunction. To illustrate, the const I've defined serves as a means of testing certain values within a function. Although there are workarounds for this problem, I find it perplexing and woul ...

Utilize API within an array to enable Ionic to display a PDF in a document viewer

Recently diving into the world of Angular and Ionic, I've come across some interesting API data: [{"ID":"1","Title":"Maritime Safety","File_Name":"9c714531945ee24345f60e2105776e23.pdf","Created":"2018-11-07 17:36:55","Modified":"2018-11-07 17:36:55"} ...

Utilizing TypeScript Variables within a Jquery Each Iteration

I have a variable named tableIndexNumber that I need to use in different methods. When trying to access this variable, I use "this.tableIndexNumber" and it works fine. However, I face an issue when using it inside a jQuery each loop because the HTML elemen ...

Limiting the number of characters in a PrimeNG Quill editor

I am currently working on implementing a maximum length for the editor. Here is the code snippet I am using: this.editorTextChange$$ = this.quillEditor.onTextChange.asObservable() .subscribe((ev) => { const limit = this.maxLength; // last cha ...

Incorporate all photographs from a designated directory in the gallery into an Angular 6 PWA Application

Currently, I am developing a Progressive Web Application that requires me to showcase all images stored under a specific directory (for instance, all pictures saved in the "Downloads" folder on a mobile device) within a personalized grid view. I would lik ...

Importing dynamically into Ionic 2 from locations other than the "node_modules" directory

I've recently reviewed the documentation for ModuleResolution in TypeScript on this page: https://www.typescriptlang.org/docs/handbook/module-resolution.html#node My understanding is that all files I wish to import must reside within the node_modules ...

Can someone confirm if I am importing this png file correctly? I am encountering an error with Vite, here is my code

Error: TypeScript+ React + Vite [plugin:vite:import-analysis] Failed to find import "./assets/heropic.png" in "src\components\Hero.tsx". Are you sure the file exists? Hello fellow developers! I am new to working with react and typescript. Curren ...

How can we properly retrieve data in order to update the user interface using the useEffect hook and useState in React

I'm diving into the world of Next.js 13 for the first time, attempting to retrieve a cart object from the API and display it on the UI. Utilizing useState to hold the cart object and useEffect to fetch it. However, upon calling setCart(), the UI fail ...

What is the process in TypeScript for defining a custom variation of a generic function?

Suppose we have a generic function: const f1 = <T>(x: T) => console.log(x) We can then create a specialized version for f1, like this: const f2 = (x: number) => f1(x) If we try to call f2 with an argument of type string, TypeScript will thr ...

Issue with accessing container client in Azure Storage JavaScript library

When working on my Angular project, I incorporated the @azure/storage-blob library. I successfully got the BlobServiceClient and proceeded to call the getContainerClient method, only to encounter this error: "Uncaught (in promise): TypeError: Failed ...

Is it possible to integrate angular-bootstrap-datetimepicker with bootstrap3?

Looking for an accessible date picker solution for my project. The project is built on Bootstrap3, but the angular-bootstrap-datetimepicker has a dependency on Bootstrap4. Can I still integrate angular-bootstrap-datetimepicker with Bootstrap3? ...