VS Code不能使用/jspm_packages; systemjs看不到angular2 ts文件 [英] VS Code can't use /jspm_packages; systemjs can't see angular2 ts files

查看:89
本文介绍了VS Code不能使用/jspm_packages; systemjs看不到angular2 ts文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSPM创建基本的Angular 2工作流程.它可以正常工作(请参见 https://github.com/simonh1000/Angular2-beta-jspm ),但是我我没有得到智能感知,因为VS Code无法看到Angular jspm模块,如图中所示.我该怎么办?

I am using JSPM to create a basic Angular 2 workflow. It works (see https://github.com/simonh1000/Angular2-beta-jspm), but I'm not getting intellisense as VS Code does not see the Angular jspm modules, as can be seen in the image. What should I do?

这是我的tsconfig.json,包括埃里克(Eric)的建议:

And here is my tsconfig.json including the suggestion from Eric:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "moduleResolution": "node"
  }
}

通过使用这种导入语句,我可以在VS Code中取得一些进步

I can make some progress in VS Code by using this sort of import statement

import { Component, View } from '../jspm_packages/npm/angular2@2.0.0-beta.0/ts/core';

但是当我运行它达到效果时,我得到一个错误:

But then I get an error when I run it to the effect:

GET http://127.0.0.1:8080/jspm_packages/npm/angular2@2.0.0-beta.0/ts/core.js

这里是config.js的摘录

Here is an extract from config.js

System.config({
  baseURL: "/",
  defaultJSExtensions: true,
  transpiler: "typescript",
  typescriptOptions: {
    "module": "commonjs",
    "emitDecoratorMetadata": true
  },
  paths: {
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },

  packages: {
    "app": {
      "main": "main",
      "defaultExtension": "ts"
    }
  },

推荐答案

由于TypeScript编译器不知道如何查找" JSPM软件包,因此目前可以预期.

This is expected at the moment because the TypeScript compiler doesn't know how to "find" JSPM packages.

VSCode依赖于TypeScript编译器,并且编译器只知道通过NPM软件包查找模块(例如,在node_modules/中查找-这就是"moduleResolution": "node"的作用).

VSCode relies on the TypeScript compiler, and the compiler only knows to look for modules through NPM packages (e.g. look inside node_modules/ - that's what "moduleResolution": "node" does).

由于尚未通过NPM安装Angular 2,因此它不在node_modules/文件夹中,并且编译器也找不到它.如果您正在运行tsc命令行编译器,则应该得到相同的错误.

Since you haven't installed Angular 2 via NPM, it's not in the node_modules/ folder and the compiler doesn't find it. You should get the same error if you were running the tsc command-line compiler.

解决方案是存在

Solutions are being discussed and it seems TypeScript@next has some basic support to manually specify a list of paths to look for modules (I haven't tested it yet). It doesn't seem ideal though as you'll have to manually maintain this list every time your JSPM dependency changes.

一种替代方法是,除了JSPM(例如npm install angular2 --save--save-dev)外,还通过NPM安装Angular 2,但这会重复依赖关系,并且在更改依赖项时也需要手动维护.

An alternative is to install Angular 2 via NPM in addition to JSPM (e.g. npm install angular2 --save or --save-dev) but that duplicates the dependency and also require manual maintenance when they change.

生命正处在流血的边缘...

Such is life at the bleeding edge...

这篇关于VS Code不能使用/jspm_packages; systemjs看不到angular2 ts文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆