问题
I've setup a new web project where I wanted to begin working/learning TypeScript. This project while an empty c#.net web project is not using MVC, angular, etc. It is just plain vanilla html and Ts. Everything was running smooth until I started setting up modules (classes, interfaces etc.) Once I started exporting and importing the modules I began receiving in the dev tools the error Uncaught ReferenceError: require is not defined
. Looking at the actual js file I can see it is wrapping the body of the file in a require().
This project is small and I don't want to setup requireJs if possible. Is there are way to disable the Ts compiler in VS to not insert the require() function? node.js is not being used and within the project properties I have switched the Modules system from CommonJS to Es2015.
Or am I totally missing something here and should be bundling these files?
I am declaring the exports and imports as:
interface.ts
import {Category } from './enums';
interface ICar {
id: number;
make: string;
model: string;
vin?: string;
mileage?: number;
category: Category;
}
export { ICar }
enum.ts
enum Category { Antique, Sportscar, Truck, SUV, Sedan };
export { Category };
and at the top of my main file app.ts I reference the modules
import { Category } from './enums';
import { ICar } from './interfaces';
Once compiled the js output in my main file app.js contains this at the header
"use strict";
var enums_1 = require("./enums");
Thanks for any advice
回答1:
You can set up typescript in visual studio project like this:
Then if you never use export or import, you will be able to work. For proper files chaining (when bundlig all together) don't forget to add your references at the top of your ts files:
/// <reference path="path/mytool.class.ts" />
来源:https://stackoverflow.com/questions/41751573/how-to-run-typescript-in-visual-studio-2015-without-require-or-requirejs