2016-09-30 64 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,它顯示了功能完整的代碼。