web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Consuming RxJS from Typescript on entity form events (onLoad)

(0) ShareShare
ReportReport
Posted on by 120

My goal is to consume onLoad and onChange from RxJS using Typescript.

I know that Dynamics 365 doesn't support Typescript and ES6 modules, which makes transpiling ES6 modules extremelly challenging.

I've been trying to get a tiny sample code to work but it seems that my transpiled code is not working. It seems that I can't figure out the right configuration to bundle my code into something that CRM/browser can understand.

Here is my code:


import { iif, of, interval } from 'rxjs';
import { mergeMap } from 'rxjs/operators';

module FUS {

    export function onLoad(executionContext: any) {
        console.log("onLoad");

        const r$ = of('R');
        const x$ = of('X');
        
        interval(1000)
          .pipe(mergeMap(v => iif(() => v % 4 === 0, r$, x$)))
          .subscribe(console.log);
    }
}

And I have uploaded RxJS as a web resource from this CDN

For Transpiling, I have used tsc, rollup and browserify, separately of course, but none of them worked for me.

  • tsc

    This is my tscongif.json

    {
      "compilerOptions": {
        "target": "ES3",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
        "module": "amd",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
        "lib": ["ES2015", "DOM"],                             /* Specify library files to be included in the compilation. */
        "outDir": "./build/opportunity",                        /* Redirect output structure to the directory. */
        "strict": true,                           /* Enable all strict type-checking options. */
        "moduleResolution": "node",            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
        "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
        "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */
      }
    }
    


  • rollup.js

    This is config

    import typescript from 'rollup-plugin-typescript';
    import resolve from '@rollup/plugin-node-resolve';
    
    export default {
      input:'src/opportunity/form.ts',
      output: {
        file: 'build/opportunity/form.js',
        format: 'amd'
        //"amd", "cjs", "system", "es", "" or "umd".
      },
      external: [ 'rxjs', 'rxjs/operators' ], 
    
      plugins: [
        typescript(),
        resolve({browser: true, mainFields: ['module']}),
      ]
    }


  • browserify

    browserify .\src\opportunity\form.ts -p [ tsify  ] --ignore rxjs > .\build\opportunity\form.js

Here are the most common errors I get:

  • require is not defined
  • define is not defined
  • rxjs is not defined
  • Cannot use import statement outside a module

There are very few blog posts about consuming Typescript with Dynamics 365 using XrmDefinitelyTyped but none of them covered consuming/bundling an npm module such as RxJS in my case.

Any guidance would be really helpful.

I have the same question (0)
  • Suggested answer
    kojisaiki Profile Picture
    on at

    I recommend to read below at first for using 3rd-party libraries.

    docs.microsoft.com/.../use-javascript

    According to above and messages you got, I recommend next action.

    - Try to embed 3rd-party code into your single file according to "Cannot use import statement outside a module".

    - Try to add some polyfill library for using modern syntax.

  • Joeri Stroy Profile Picture
    20 on at

    Hi Ahmad,

    did you ever find a solution for this?

    I'm currently struggling with the exact same issue.

    regards

  • Ahmad Anwar Profile Picture
    120 on at

    Unfortunately, no success.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans