当前位置: 首页 > 知识库问答 >
问题:

gulp-typescript给出模块找不到angular2错误

王杰
2023-03-14
paths.appJs = "app/**/*.ts";
paths.appNg2ComponentsJs = "ng2components/**/*.ts";
paths.appHtml = "app/**/*.html";
paths.appJsOut = paths.webroot + "app/";
paths.angualr2Typings = "node_modules/angular2/typings/";

gulp.task("compile-app-components", function () {

    var tscResult = gulp.src([paths.appNg2ComponentsJs, paths.angualr2Typings + "**/*.d.ts"])
        .pipe(tsc({
            "target": "es5",
            "module": "system",
            "declaration": false,
            "noImplicitAny": false,
            "removeComments": true,
            "noLib": false,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "sourceMap": true,
            "listFiles": true,
        }));

    return tscResult.js
        .pipe(gulp.dest(paths.appJsOut));
});

共有1个答案

鲁杜吟
2023-03-14

首先,不应将.d.ts定义文件添加到gulp构建任务中:

paths.appJs = "app/**/*.ts";
paths.appNg2ComponentsJs = "ng2components/**/*.ts";
paths.appHtml = "app/**/*.html";
paths.appJsOut = paths.webroot + "app/";

gulp.task("compile-app-components", function () {    
    var tscResult = gulp.src([paths.appNg2ComponentsJs, paths.appJs])
        .pipe(tsc({
            "target": "es5",
            "module": "system",
            "declaration": false,
            "noImplicitAny": false,
            "removeComments": true,
            "noLib": false,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "sourceMap": true,
            "listFiles": true
        }));

    return tscResult.js
        .pipe(gulp.dest(paths.appJsOut));
});

而且,您需要编写

///<reference path="path/to/file.d.ts" />

.ts脚本开头的行(即paths.appjs中的行),这些行是必需的(TypeScript编译器在不知道标识符时会告诉您)。

 类似资料:
  • 问题内容: 我正在使用angular2和gulp开发一个节点应用程序。我编写了一个组件文件login.ts,如下所示: 我的bootstrap.ts文件是: 但是当我编译这些文件时,出现以下错误: 这是我的tsconfig.json: 我已经使用以下命令安装了angular2的类型: 请帮助纠正错误。 问题答案: @simon错误说的是输入错误。但是对于其他进口商品,我已经发布了此答案,可能对其他

  • 我试图找到此错误的任何解决方案,但没有任何对我有用。我有一个简单的Angular2应用程序,使用Angulal-CLI创建。当我在浏览器中提供此应用程序时,我收到此错误:我正在尝试在加载中使用不同的路径儿童: 文件夹 应用程序模块 app-routing.module.ts test.module.ts 堆栈跟踪

  • 我收到的错误是: 错误:无法从'f:...\newstyle\assets\lib\helper\html\img\js' 在C:\users...\appdata\roaming\npm\node_module\browserify\node_module\srowserify\browser-resolve\node_module\srowser-resolve\lobers\lib\asyn

  • 我对Angular2是新手。我正在学习。这是第一个简单的教程,叫做猜数字 我使用了github提供的示例https://github.com/chandermani/angular2byexample/tree/master/guessthenumber中描述的代码。 它在浏览器中加载得很好。我有问题的是IntelliJ设置。 IntelliJ返回以下错误。如截图所示。找不到模块“@Angular

  • config:macOS High Sierra,version 10.13.2,node:v8.1.2 npm:5.0.3当我在angularjs项目中运行npm start时,我得到以下错误: 在此之后我运行: 现在我得到了这个错误: 为什么npm不安装Node-Sass?如何安装Node-Sass?

  • 问题内容: Mac OSX El capitan | angular-cli:0.1.0 | 节点:5.4.0 | 操作系统:darwin x64 我尝试根据angular-cli Wiki安装第三方npm模块:https : //github.com/angular/angular-cli/wiki/3rd-party- libs 但失败。我已经为此苦苦挣扎了好几天了,非常感谢您的帮助。 得到错