2017-04-24 4 views
2

が定義されていません。/node_modules/.binファイルを実行した後角度AOT&ロールアップ - キャッチされないにReferenceError:NGC一部の作品を使用して <a href="https://angular.io/docs/ts/latest/cookbook/aot-compiler.html" rel="nofollow noreferrer">https://angular.io/docs/ts/latest/cookbook/aot-compiler.html</a></p> <p>、それはAOTのフォルダを生成します。輸出は、私は角度のAOTのチュートリアルを実装しようとしています

のTSconfig-aot.json

{ 
     "compilerOptions": { 
     "target": "es5", 
     "module": "es2015", 
     "moduleResolution": "node", 
     "sourceMap": true, 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "lib": ["es2015", "dom"], 
     "noImplicitAny": true, 
     "suppressImplicitAnyIndexErrors": true 
     }, 

    "files": [ 
    "src/app/app.module.ts", 
    "src/main.ts" 
    ], 

     "angularCompilerOptions": { 
     "genDir": "aot", 
     "skipMetadataEmit" : true 
    }, 
    "exclude": [ 
      "node_modules", 
      "bower_components", 
      "typings/main", 
      "typings/main.d.ts" 
     ] 
    } 

- :しかし、私は、アプリケーションを実行すると、私は

bundle.js:1 Uncaught ReferenceError: exports is not defined 

以下のエラーを取得する私のコードは以下の通りですngc -p tsconfig-aot.json、aotフォルダは正常に生成されました。私は、のいずれかで読ん

main.ts

import { platformBrowser } from '@angular/platform-browser'; 
import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory'; 
console.log('Running AOT compiled'); 
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); 

はSOこれがなければならないことを意味する。木振る 『「から利益を得るために、あなたはes2015モジュールとしてこれらのTSファイルをコンパイルする必要がある』というリンクmain-aot.tsファイルだけを指し示すconfigファイル(tsconfig-compile-aot.json)がもう1つあります。

のTSconfig - コンパイル - aot.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "es2015", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": ["es2015", "dom"], 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true 
    }, 

    "files": [ 
    "src/main.ts" 
    ], 

    "angularCompilerOptions": { 
    "genDir": "aot", 
    "skipMetadataEmit" : true 
}, 
"exclude": [ 
     "node_modules", 
     "bower_components", 
     "typings/main", 
     "typings/main.d.ts" 
    ] 
} 

、TSCとのTSconfig-コンパイルaot.jsonとメインaot.tsファイルをコンパイルし、再びes2015モジュールなど、あなたのjsファイルを生成します。コンパイルに私は、私は、コマンド
tsc src/main.ts

ロールアップ-config.jsの私は、以下のコマンドを実行した。その後

import rollup  from 'rollup' 
import nodeResolve from 'rollup-plugin-node-resolve' 
import commonjs from 'rollup-plugin-commonjs'; 
import uglify  from 'rollup-plugin-uglify' 

export default { 
    entry: 'src/main.js', 
    dest: 'bundle.js', // output a single application bundle 
    sourceMap: false, 
    format: 'iife', 
    onwarn: function(warning) { 
    // Skip certain warnings 
    // should intercept ... but doesn't in some rollup versions 
    if (warning.code === 'THIS_IS_UNDEFINED') { return; } 
    // console.warn everything else 
    console.warn(warning.message); 
    }, 
    plugins: [ 
     nodeResolve({jsnext: true, module: true}), 
     commonjs({ 
     include: 'node_modules/rxjs/**', 
     }), 
     uglify() 
    ] 
} 

を実行し、私のjsファイル 取得/ .binファイル/ロールアップ-c rollup- node_modules config.js

npm run liteを実行すると、エラーが発生します。

+0

私は 'TSconfigの-aot.json'と' TSconfigの-コンパイルaot.json'すでに最初のものとの違いが表示されません'es2015'モジュールタイプを持っています – yurzui

+0

生産のためにロールアップ設定に' main-aot'エントリーポイントがあるべきです – yurzui

+0

@yurzui:申し訳ありませんが、違いはファイルセクションとその単なる名前です。私のmain.tsの内容はaotに応じて変更されており、メインアotはありません – Shifs

答えて

1

あなたのマスターページに次のコードを追加する必要があります。

window.module = { 
    id: 'foo', 
    exports: [] 
} 
関連する問題