Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Esbuild with ReactJS.NET?

TL;DR How can I use esbuild with ReactJS.NET?


Long version

ReactJS.NET expects the following from a "bundle":

React.Exceptions.ReactNotInitialisedException: 'React has not been loaded correctly: missing (React, ReactDOM, ReactDOMServer). Please expose your version of React as global variables named 'React', 'ReactDOM', and 'ReactDOMServer'

What Webpack actually does is always quite unclear to me, but looking at the ReactJS.NET Webpack tutorial here, this is the setup:

import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';

import RootComponent from './home.jsx';

global.React = React;
global.ReactDOM = ReactDOM;
global.ReactDOMServer = ReactDOMServer;

global.Components = { RootComponent };

Further at the sample webpack-config here, there is this output-setting:

{
  [...]
  globalObject: 'this',
}

Mirroring this in esbuild would be using iife and esbuild.globalName = 'this', but it throws an error:

 > (global name):1:0: error: Expected identifier but found "this"
    1 │ this

Esbuild is quite stern on that it is a bundler (not a transpile-and-concatenator), so how would I tweak Esbuild to have the bundle mutate the global object to what React.NET expects? - And is it even possible?

Thanks, Flemming

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found a solution.

import { build } from 'esbuild'

const globalName = 'whatever'

build({
    [...]
    format: 'iife',
    globalName,
    footer: {
        // Important! Assigns the raw export of the bundle to whatever `this` is in the given context
        js: `Object.assign(this, ${globalName})`,
    },
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!