首页 文章

Angular 2在Sublime Text 3中有错误

提问于
浏览
6

我尝试在Windows上的Angular 2中基于以下存储库启动一个新项目:https://github.com/mgechev/angular2-seed

一切正常( npm installnpm start ,...),但Sublime Text 3显示了我执行项目时不存在的一些错误 .

以下是我遵循的步骤:

$ git clone https://github.com/mgechev/angular2-seed.git
$ cd angular2-seed
$ npm install

然后我用Sublime Text(带有TypeScript package)打开项目,我在代码中面临一些错误/警告 .

错误#1

带有 @Component 装饰器的类显示以下错误:

对装饰器的实验支持是一个在将来的版本中可能会发生变化的功能 . 设置'experimentalDecorators'选项以删除此警告 .

(它忽略了tsconfig.json中的 "experimentalDecorators": true 行)

错误#2

例如,在src / client / app / about / about.component.ts中,在行上:

moduleId: module.id,

Sublime显示此错误:

找不到名称'模块' .

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "es2015", "dom"],
    "sourceMap": true,
    "pretty": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitUseStrict": false,
    "noFallthroughCasesInSwitch": true,
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules"
    ],
    "types": [
      "node"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "src"
  ],
  "compileOnSave": false
}

package.json

https://github.com/mgechev/angular2-seed/blob/27db8a19f70470f5110482df1a4debc1100ec347/package.json

你为什么我有这2个错误?我可以发展,但不是很愉快 .

3 回答

  • 1

    由于这个链接,我解决了我的问题:https://github.com/Microsoft/TypeScript-Sublime-Plugin/issues/470

    总结一下:

    • 转到用户首选项(Ctrl Shift P>首选项:设置)

    • 添加以下行: "typescript_tsdk": "C:/...../npm/node_modules/typescript/lib", (带有相应的链接)

    • 重新启动Sublime文本

    • 当光标在 module.id 上时按F12测试它是否在about.component.ts文件中有效

    • 享受!

  • 19

    我会用完全相同的问题添加我的发现 .

    我将我的前端应用程序带到服务器端文件结构(我使用flask作为我的服务器端引擎),问题再次出现 . 我已经使用从系统范围改变tsc路径到 /frontend/node_modules/typescript/bin/tsc 解决了它 - 即我在项目中使用的打字稿的本地版本 . 这解决了我的问题 - 现在 .

  • 0

    我很难找到我的打字稿文件,因为它巧妙地伪装成“tsc”但我的位于:

    C:\Users\Mike\AppData\Roaming\npm\node_modules\typescript\lib
    

    为了找到它,我运行了命令:

    where tsc
    

相关问题