简体   繁体   English

为Angular2应用程序转译ts文件时出错

[英]Errors when transpiling ts files for an Angular2 application

I try to use TypeScript with Angular. 我尝试将TypeScript与Angular结合使用。 For this, I transpile my ts files using the tsc command and I have some errors. 为此,我使用tsc命令转换ts文件,但出现一些错误。 That said, the files are actually transpiled into JavaScript and I can make work my application but these errors are a bit strange.... 就是说,这些文件实际上已经被转换为JavaScript,并且我可以使我的应用程序正常工作,但是这些错误有点奇怪。

Here is what I have: 这是我所拥有的:

app.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
app.ts(1,42): error TS2307: Cannot find module 'angular2/angular2'.
app.ts(13,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.

Here is the content of the tsd.json file: 这是tsd.json文件的内容:

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/tsd.d.ts",
  "installed": {
    "angular2/angular2.d.ts": {
      "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304"
    }
  }
}

Here is the content of the tsdconfig.json file: 这是tsdconfig.json文件的内容:

{
  "compilerOptions" : {
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "target": "es5"
  },
  "files" : [
    "app.ts",
    "typings/angular2/angular2.d.ts"
  ]
}

To compile, I execute the command: tsc --watch *.ts . 要编译,我执行命令: tsc --watch *.ts My ts files are located at the root of my project. 我的ts文件位于项目的根目录。

Thanks very much for your help, Thierry 非常感谢您的帮助,蒂埃里

First, if you specify file(s) in tsc command, tsconfig.json file is ignored . 首先,如果您在tsc命令中指定文件,则tsconfig.json文件将被忽略 You can learn more about it here . 您可以在此处了解更多信息。 So you should invoke command: tsc -w . 因此,您应该调用命令: tsc -w Second, you do not have to include typings in your files, they are just for intellisense in your editor(and angular2 includes its typings by default). 其次,您不必在文件中包含类型,它们仅用于编辑器中的智能感知(默认情况下,angular2包括其类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在转换Angular2 TS时配置gulp-typescript以使用JSPM - How to configure gulp-typescript to work with JSPM when transpiling Angular2 TS Angular2-在不同文件中拆分应用程序时出现参考错误 - Angular2 - Reference error when splitting application in different files TypeScript / Angular2:rxjs错误TS1138,TS1005,TS1128 - TypeScript/Angular2: rxjs errors TS1138, TS1005, TS1128 转译时排除 *.spec.ts 文件但仍然正确地整理它们 - Exclude *.spec.ts files when transpiling but still lint them properly Angular2如何确保使用更新的ts / js文件? - Angular2 how to ensure using updated ts/js files? MSBuild是否有必要在Angular2的依赖项中(在node_modules中)转换.ts文件以使Angular2正常工作? - Is it necessary for MSBuild to transpile .ts files in Angular2's dependencies (in node_modules) for Angular2 to work? 在带有Angular2和.ts规范的量角器中使用“ ReferenceError:系统未定义” - “ReferenceError: System is not defined” when using protractor with Angular2 and .ts specs 在普通TS类中声明时Angular2 Router抛出错误 - Angular2 Router throwing error when declared in normal TS class 带有TS的Angular2模块系统 - Angular2 module system with TS 使用angular2.api.ts时,“未将模块angular2 / src / core / compiler / interfaces声明为依赖项” - “Module angular2/src/core/compiler/interfaces not declared as a dependency” when using angular2.api.ts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM