Good day,
I am trying use ReactJS with Typescript. Everything looks good, but after starting the application error occurs: "Can't find variable: require"
I not use node.js for server side rendering.
Script:
/// <reference path="../typings/tsd.d.ts"/>
import * as React from 'react'
import * as ReactDom from 'react-dom'
interface Props {}
interface State {}
export class App extends React.Component<Props, State>{
render(){
return (<div>Hello</div>);
}
}
ReactDom.render(<App/>, document.getElementById("content"));
and this compiled boot.js:
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require('react');
var ReactDom = require('react-dom');
var App = (function (_super) {
__extends(App, _super);
function App() {
_super.apply(this, arguments);
}
App.prototype.render = function () {
return (React.createElement("div", null, "Ahoj"));
};
return App;
}(React.Component));
exports.App = App;
ReactDom.render(React.createElement(App, null), document.getElementById("content"));
Error:

You're going to need module resolution. require is a form of loading a module into your code. It's usually used with NodeJS. If you want to use it in the browser, try Browserify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With