typescript-uncaught referenceError:未定义require

时间:2017-01-06 20:44:23

标签: typescript visual-studio-2015 enums

Visual Studio 2015更新3。 我收到了错误:

import { Category } from "./Enums"; at runtime.

在:

export enum Category { Biography, Poetry, Fiction, History, Children }

Solution-app.ts-Enums.ts-Interface.ts-tsconfig.ts pictures

我真的不明白为什么我会收到这个错误(我对Typescript很新)

enums.ts:

import { Category } from './enums';
export interface Book {
    id: number;
    title: string;
    author: string;
    available: boolean;
    category: Category;
    pages?: number;
    markDamaged?: DamageLogger;
}

interface.ts:

import { Category } from './enums';
import { Book, DamageLogger, Author, Librarian } from './interfaces';
import { UniversityLibrarian } from './classes';

function GetAllBooks(): Book[] {

    let books = [
        { id: 1, title: 'Ulysses', author: 'James Joyce', available: true, category: Category.Fiction },
        { id: 2, title: 'A Farewell to Arms', author: 'Ernest Hemingway', available: false, category: Category.Fiction },
        { id: 3, title: 'I Know Why the Caged Bird Sings', author: 'Maya Angelou', available: true, category: Category.Poetry },
        { id: 4, title: 'Moby Dick', author: 'Herman Melville', available: true, category: Category.Fiction }
    ];

    return books

app.ts:

def getRankingsFromGoogle(keyword, website, page = 1, count = 1): 

   if count is 5: 
   print "NOT ON PAGE 5" 

2 个答案:

答案 0 :(得分:1)

您需要安装节点

的类型
npm i -D @types/node

require definition is in there

答案 1 :(得分:0)

我使用" outFile"解决了这个错误。在tsconfig.json中。 如果我们使用" outFile"我们不应该使用" module":" commonjs",我们应该只使用" amd"和"系统"