2016-09-30 80 views
1

我使用rollupjs作为新[email protected]版本的一部分。该项目使用tsconfig.jsoncompilerOptions.module = "es2015"而不是"commonjs",这对我来说是全新的。导入rollupjs,es2015模块

// typescript 
import { AgmCoreModule } from 'angular2-google-maps/core'; 

我从汇总得到这个import错误

[17:40:45] typescript compiler finished in 8.08 s 
[17:40:45] bundle dev started ... 
[17:40:55] Error: Module .../node_modules/angular2-google-maps/core/index.js does not export AgmCoreModule (imported by .../.tmp/shared/shared.module.js) 
    at Module.trace (.../node_modules/rollup/dist/rollup.js:7677:29) 
    at ModuleScope.findDeclaration 
    ... 

导入文件看起来像这样

// index.d.ts 
/** 
* angular2-google-maps - Angular 2 components for Google Maps 
* @version v0.14.0 
* @link https://github.com/SebastianM/angular2-google-maps#readme 
* @license MIT 
*/ 
export * from './directives'; 
export * from './services'; 
export * from './map-types'; 
export { LatLngBounds, LatLng, LatLngLiteral, MapTypeStyle } from './services/google-maps-types'; 
export * from './core-module'; 


// index.js 
/** 
* angular2-google-maps - Angular 2 components for Google Maps 
* @version v0.14.0 
* @link https://github.com/SebastianM/angular2-google-maps#readme 
* @license MIT 
*/ 
"use strict"; 
function __export(m) { 
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; 
} 
// main modules 
__export(require('./directives')); 
__export(require('./services')); 
// Google Maps types 
// core module 
__export(require('./core-module')); 

//# sourceMappingURL=index.js.map 

我可以在我的进口改为

import { AgmCoreModule } from 'angular2-google-maps/core/core-modules'; 

rollup没有抱怨,但angular2没有找到从angular2-google-maps/core

导入的指令我该怎么办?

+0

你是如何导入指令的?在我的NgModule注释中简单地添加“AgmCoreModule.forRoot()”到导入[]中(我还需要导入'angular2-google-maps/core/core-modules'tho) – Jamby

+0

这就是我所做的,但我为'shared.modules.ts'和'app.modules.ts'添加'[AgmCoreModule.forRoot()]'' – michael

+0

当然可以。它在angular2-google-maps的入门 – Jamby

回答

1

当使用__export函数将angular2-google-maps/core/index.ts中的export * from ...声明编译为JS时,Rollup失去了跟踪导出哪些绑定的能力。如果您改为使用esm/(ECMAScript模块)目录中的可用库的ES6版本,那么一切都应该工作。

import { AgmCoreModule } from 'angular2-google-maps/esm/core/index.js'; 
+0

我仍然得到这些错误'错误TS2307:无法找到模块'angular2-google-maps/esm/core/index.js'.'或错误TS2307:无法找到模块' ../../ node_nodules/angular2-google-maps/esm/core/index.js'.' TS没有抱怨这个问题:'从'angular2-google-maps/core/core-import'导入{AgmCoreModule}模块;' – michael

0

对于候选版本,离子2从基于吞-构建过程一个现在使用rollup.js用于捆绑移动。大多数情况下,第三方库“正常工作” - 但是在某些情况下(取决于库如何导出其组件),您需要明确告诉rollup.js要导出的内容。这是Angular 2谷歌地图在这里发生的事情。

这是在Ionic 2 App Build Scripts文档页面的“Building”部分中记录的。 总之,您需要为您的项目创建一个自定义rollup.config.js文件,以告诉Rollup约AgmCoreModule

这是一个blog post,它完全记录了确切的步骤。另外,这里是一个Github repo,它显示了功能完整的代码。