title: Can I use requirejs to load modules in typescript code?
body: <p>I'm using typescript and requirejs.  I want to import my library code as modules, to avoid making everything an ambient global.  My problem is that any use of import or export in a typescript file turns the entire file into a module.  In the case of my application code, this means it can't be invoked directly.</p>
  
  <p>Here's a sample app.</p>
  
  <h2>index.html</h2>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;My Test App&lt;/title&gt;
          &lt;script src="require.js"&gt;&lt;/script&gt;
          &lt;script src="app1.js"&gt;&lt;/script&gt;
          &lt;script src="app2.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>tsconfig.json</h2>
  
  <pre><code>{
      "compilerOptions": {
          "module": "amd",
          "target": "es5",
          "noImplicitAny": false,
          "sourceMap": false
      }
  }
  </code></pre>
  
  <h2>greeter.ts</h2>
  
  <pre><code>export function greet(name: string) {
      alert(`Hello ${name}`);
  }
  </code></pre>
  
  <h2>app1.ts</h2>
  
  <pre><code>import { greet } from './greeter';
  greet('alice');
  </code></pre>
  
  <h2>app2.ts</h2>
  
  <pre><code>import { greet } from './greeter';
  greet('bob');
  </code></pre>
  
  <p><code>tsc</code> runs with no problem, but here's one of the files I get as output.</p>
  
  <h2>tsc output: app1.js</h2>
  
  <pre><code>define(["require", "exports", './greeter'], function (require, exports, greeter_1) {
      "use strict";
      greeter_1.greet('alice');
  });
  </code></pre>
  
  <p>That doesn't work.  From <a href="http://requirejs.org/docs/errors.html#mismatch" rel="nofollow noreferrer">require.js</a> </p>
  
  <blockquote>
    <p>Be sure to load all scripts that call define() via the RequireJS API.
    Do not manually code script tags in HTML to load scripts that have
    define() calls in them.</p>
  </blockquote>
  
  <p>So how can I convince the typescript compiler to produce output without a <code>define()</code> call in it.  In app1.ts, I don't intend to define a module, just consume other modules.  <code>require()</code> seems more appropriate for that.  Is there a way to make <code>import</code> compile to <code>require()</code>?</p>