Creating Production Files for Web using RxJs and TypeScript

I am interested in developing a JavaScript Library using RxJs (5.0.0-Beta.6) and TypeScript (1.8.10).

My TypeScript file is successfully compiling. Below are the files I have:

MyLib.ts:

/// <reference path="../../typings/globals/es6-shim/index.d.ts" />
import * as Rx from 'rxjs/Rx';
Rx.Observable.of('foo', 'bar');

tsconfig.json:

{
    "compilerOptions": {
         "module": "commonjs"
        ,"target": "es5"
        ,"sourceMap": true
    },
    "files": [
         "src/MyLib.ts"
    ]
}

I use gulp-typescript to generate the JS file, which results in:

MyLib.js:

"use strict";
var Rx=require("rxjs/Rx");
Rx.Observable.of("foo","bar");

To incorporate this file into an HTML document, I need to include its dependencies:

  • RxJs 5.0.0 Beta 6 >> node_modules/rxjs/bundles/Rx.min.js

  • SystemJS 0.19.38 >> node_modules/systemjs/dist/system.js

  • RequireJS 2.3.2 >> node_modules/requirejs/require.js

This is my HTML:

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8>
    <title>MyLib Test</title>

    <script src="vendor/require.js"></script>
    <script src="vendor/system.js"></script>
    <script src="vendor/Rx.min.js"></script>
    <script src="MyLib.js"></script>

</head>
<body>

</body>
</html>

Issue Faced:

Upon checking the Chrome Console, I encountered the following error:

Uncaught Error: Module name "rxjs/Rx" has not been loaded yet for context: _. Use require([])

I am unable to load the simple JavaScript file MyLib.js created with RxJs and TypeScript. How can I resolve this problem?

Answer №1

Don't forget to properly set up your module loader (and make sure you only have one of them - either require or systemjs).

To fix this issue, remove the unnecessary module loader and adjust your html code using systemjs like so:

<!DOCTYPE html>
<html lang="en>
<head>
    <meta charset="UTF-8>
    <title>MyLib Test</title>
    <script src="vendor/system.js"></script>
    <script>
        System.config({
            paths: {
                "rxjs": 'vendor/rx/dist/rx.min'
            }    
        });

        System.defaultJSExtensions = true;

        //This will bootstrap your app
        System.import('myLib').catch(function(e)
        {
            console.error(e);
        });
    </script>
</head>
<body>

</body>
</html>

I hope this resolves your issue.

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

Sequential Element Loading using jQuery upon pageload

Can someone please explain how to achieve the effect shown on this website: http://www.getflow.com/ ? I believe that jQuery is being used to gradually adjust the opacity of each element. Is there a simple JavaScript snippet available to load each image e ...

Header-driven redirection

I am using node js and express js. My goal is to ensure that if app.get does not have a token parameter, then an html file with js will be uploaded to pass the token. If the token is passed, then another html file should be displayed. However, I am unsure ...

Creating a compact Swiper slider: reducing image size without sacrificing full window coverage!

Utilizing Swiper to craft a slider that occupies the entire window, with a slight margin for a bar-- no issues there. (https://i.sstatic.net/qcGBA.jpg) However, the image I placed in for the slide () appears to be excessively enlarged. Is there a way to ...

Summoning within a rigorous mode

I am facing an issue with my configuration object: jwtOptionsProvider.config({ tokenGetter: (store) => { return store.get('token'); }, whiteListedDomains: ['localhost'] }); In strict mode, I ...

MeteorJS: Verification of User Email addresses

After sending an email verification to a user, how can I ensure they actually verify their email after clicking on the link sent to their address? I'm aware of this function Accounts.onEmailVerificationLink but I'm unsure of how to implement i ...

Refine the table by selecting rows that contain a specific value in the href attribute of the <a> tag, and display the parent row when the child row

I've been working on filtering and searching the table below based on the href value. My code successfully filters the displayed columns in the table, but it fails to work when I search for a string within the href attribute. For instance, if I searc ...

Creating a one-of-a-kind entry by adding a number in JavaScript

I am looking for a way to automatically add an incrementing number to filenames in my database if the filename already exists. For example, if I try to add a file with the name DOC and it is already present as DOC-1, then the new filename should be DOC-2. ...

Enhance the code for updating the content within a div element

I recently discovered that utilizing jQuery allows for updating the content within a div. My goal now is to enhance this script so the content remains consistent, even while loading or not. Take a look at my current code: function changeContent () { va ...

Establish a predetermined selection for a radio button and its associated checkbox option

I am working on a React material UI group input field that is mapping a dataset. The result consists of one radio button and one checkbox performing the same action. Initially, I attempted to set the state to establish one data item as default. While I fol ...

When the down arrow key is pressed, the focus of the radio button is lost

I've been facing a persistent accessibility issue with the main-component in Angular. This component contains four different templates, but depending on the radio button selection, other templates are displayed. The problem arises when these templates ...

AngularJS - Ensuring the <script> tag is included only after all directives have been rendered

Forgive me if this question has been asked before. I've spent quite some time looking for a solution to no avail. I'm in the process of converting an existing application, which relies heavily on jQuery, to utilize AngularJS. However, I've ...

Utilizing Session storage throughout an Angular 2 application

I currently store a session variable as a JSON value in my home.component.ts. This variable needs to be accessed in various locations within the application. This is my code snippet: .do(data => sessionStorage.setItem('homes', JSON.stringif ...

The functionality of `import { Dialogs } from "@nativescript/core"; seems to be malfunctioning

For my project, I am in need of using Dialogs. Unfortunately, the import from @nativescript/core as mentioned in their documentation is not working. I keep encountering this error: Module '"@nativescript/core"' has no exported member &a ...

Navigate to Element ID with Nuxt.js on click

Currently, I am in the process of developing a Nuxt application and facing a challenge. I want the page to automatically scroll down to a specific element after clicking on a button. Interestingly, the button and the desired element are located within diff ...

Troubleshooting the malfunctioning of the Bootstrap slide animation

I've been attempting to implement scroll animation on a div, but for some reason, it's not working as intended. I must have made a mistake somewhere, but I can't figure out where. Any help in resolving this issue would be greatly appreciated ...

Updating a database on ASP.NET without the need to refresh the page

We are developing a user-friendly application with ASP.NET MVC that focuses on uploading pictures and rating them. The app includes two voting buttons, "like" and "dislike". https://i.sstatic.net/Z3dp5.png Whenever the like button (green) is clicked, the ...

Encountering a "file or directory not found" error during the installation of ply using

I recently stumbled upon an interesting project for testing Rest APIs. I was in the process of installing ply from https://github.com/ply-ct/ply npm install ply-ct --save-dev Encountered this error, wondering if anyone has a solution npm WARN saveError EN ...

The q library ensures that a value is delivered to the done method

I am seeking to understand the purpose and usage of the `done` method in the Q library promises. If `done` is able to receive a value or function through `resolve` or `reject`, could someone clarify how the `done` method is invoked and how arguments can ...

Having difficulty passing the new state value using props in ReactJS

I am facing an issue with sending state values from parent to child components. Initially, the state value is empty but after making an API call, the state value gets updated. However, the props in my child component are still stuck with the initial empty ...

What methods can be used to identify the pattern entered by the user for data types such as `Int`, `VarChar`, `

I have a dropdown menu containing data types. There is also a text box for entering Regex patterns. If "/test/" is entered in the textbox or "Int" is selected from the dropdown, then it's an incorrect pattern. If "/[0-9]/" is entered in the ...