[英]VS Code can't use /jspm_packages; systemjs can't see angular2 ts files
我正在使用JSPM创建一个基本的Angular 2工作流程。 它可以工作(请参阅https://github.com/simonh1000/Angular2-beta-jspm ),但我没有得到intellisense,因为VS Code没有看到Angular jspm模块,如图中所示。 我该怎么办?
这是我的tsconfig.json
包括Eric的建议:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"moduleResolution": "node"
}
}
我可以通过使用这种import语句在VS Code中取得一些进展
import { Component, View } from '../jspm_packages/npm/angular2@2.0.0-beta.0/ts/core';
但是当我运行它时,我得到一个错误:
GET http://127.0.0.1:8080/jspm_packages/npm/angular2@2.0.0-beta.0/ts/core.js
这是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包。
VSCode依赖于TypeScript编译器,编译器只知道通过NPM包查找模块(例如查看node_modules/
- 这就是"moduleResolution": "node"
node_modules/
"moduleResolution": "node"
所做的)。
由于您尚未通过NPM安装Angular 2,因此它不在node_modules/
文件夹中,并且编译器找不到它。 如果您正在运行tsc
命令行编译器,则应该得到相同的错误。
正在 讨论解决方案,似乎TypeScript @ next有一些基本的支持来手动指定寻找模块的paths
列表(我还没有测试过它)。 它似乎并不理想,因为每次JSPM依赖项更改时您都必须手动维护此列表。
另一种方法是除了JSPM之外还通过NPM安装Angular 2(例如npm install angular2 --save
或--save-dev
),但这会重复依赖性,并且在更改时也需要手动维护。
这就是生活在前沿......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.