打字稿如何知道 systemJS 配置
How does typescript know about the systemJS config
我正在 ASP.Net 核心项目中构建 Angular2 应用程序。我将 systemJS 配置为映射第三方模块,但出现编译错误。
我的 index.html 引用了 systemJS.config.js 文件,我认为它是正确的。但是,index.html 是一个运行时文件,我认为打字稿编译器不知道它。
typescript 如何在编译时了解 systemjs(及其配置)?
第三方模块之一是 ng2-file-upload。
systemjs.config.js 有这个:
var map = {
'app': 'lib/spa', // 'dist',
'rxjs': 'lib/js/rxjs',
'angular2-in-memory-web-api': 'lib/js/angular2-in-memory-web-api',
'@angular': 'lib/js/@angular',
'ng2-file-upload': 'lib/js/ng2-file-upload/ng2-file-upload'
};
var config = {
defaultJSExtensions: true,
map: map,
packages: packages
}
System.config(config);
这是从 index.html 引用的:
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
在我的组件中,我使用这样的导入:
import {FILE_UPLOAD_DIRECTIVES, FileUploader} from 'ng2-file-upload';
我收到这个编译器错误:
error TS2307: Cannot find module 'ng2-file-upload'.
我的想法是 typescript 不知道 systemJS 映射中的 ng2-file-upload 别名设置。打字稿是怎么知道的?
给你。
typescript 是如何在编译时知道 systemjs(及其配置)的?
你的项目中可能有一个 typings 文件夹,它应该包含 systemjs 的定义,它可以让你获得智能感知。对于编译,Typescript 遵循 Module Resolution - Typescript.
的约定
对于第 3 方库 ng2-file-upload
我看到您的系统配置文件中有如下配置,我猜您在构建时将此模块的文件从 node_modules 放到 lib/js文件夹。
'ng2-file-upload': 'lib/js/ng2-file-upload/ng2-file-upload'
理想情况下,如果您的项目中有 node_modules,Typescript 将使用 Module Resolution 约定解析它。
如果你没有常规的文件夹结构打字稿可能无法解析模块,
但是您可以包括 --noResolve
使用 --noResolve
通常情况下,编译器会在开始编译过程之前尝试解析所有模块导入。每次成功解析到文件的导入时,该文件都会添加到编译器稍后将处理的文件集中。
--noResolve 编译器选项指示编译器不要将任何未在命令行上传递的文件“添加”到编译中。它仍然会尝试将模块解析为文件,但如果未指定文件,则不会包含它。
不确定上述方法,您可能需要尝试看看。
我正在 ASP.Net 核心项目中构建 Angular2 应用程序。我将 systemJS 配置为映射第三方模块,但出现编译错误。
我的 index.html 引用了 systemJS.config.js 文件,我认为它是正确的。但是,index.html 是一个运行时文件,我认为打字稿编译器不知道它。
typescript 如何在编译时了解 systemjs(及其配置)?
第三方模块之一是 ng2-file-upload。
systemjs.config.js 有这个:
var map = {
'app': 'lib/spa', // 'dist',
'rxjs': 'lib/js/rxjs',
'angular2-in-memory-web-api': 'lib/js/angular2-in-memory-web-api',
'@angular': 'lib/js/@angular',
'ng2-file-upload': 'lib/js/ng2-file-upload/ng2-file-upload'
};
var config = {
defaultJSExtensions: true,
map: map,
packages: packages
}
System.config(config);
这是从 index.html 引用的:
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
在我的组件中,我使用这样的导入:
import {FILE_UPLOAD_DIRECTIVES, FileUploader} from 'ng2-file-upload';
我收到这个编译器错误:
error TS2307: Cannot find module 'ng2-file-upload'.
我的想法是 typescript 不知道 systemJS 映射中的 ng2-file-upload 别名设置。打字稿是怎么知道的?
给你。
typescript 是如何在编译时知道 systemjs(及其配置)的?
你的项目中可能有一个 typings 文件夹,它应该包含 systemjs 的定义,它可以让你获得智能感知。对于编译,Typescript 遵循 Module Resolution - Typescript.
的约定对于第 3 方库 ng2-file-upload
我看到您的系统配置文件中有如下配置,我猜您在构建时将此模块的文件从 node_modules 放到 lib/js文件夹。
'ng2-file-upload': 'lib/js/ng2-file-upload/ng2-file-upload'
理想情况下,如果您的项目中有 node_modules,Typescript 将使用 Module Resolution 约定解析它。
如果你没有常规的文件夹结构打字稿可能无法解析模块,
但是您可以包括 --noResolve
使用 --noResolve
通常情况下,编译器会在开始编译过程之前尝试解析所有模块导入。每次成功解析到文件的导入时,该文件都会添加到编译器稍后将处理的文件集中。
--noResolve 编译器选项指示编译器不要将任何未在命令行上传递的文件“添加”到编译中。它仍然会尝试将模块解析为文件,但如果未指定文件,则不会包含它。
不确定上述方法,您可能需要尝试看看。