私はプレレンダーノードとプライベートプレレンダーサーバーを使ってAngular2/Expressアプリケーションをプリレンダーしようとしています。私は私のtsconfig.jsonでES5をターゲットにしようとした場合、事前レンダリングサーバは、このエラーがスローされます。Angles2/Typescript/Webpackのプレレンダーes6エラー
ReferenceError: Can't find variable: Map
undefined:1521 in KeyRegistry
:1540
:7
私は(files
配列でnode_modules/typescript/lib/lib.es6.d.ts
含む)ES6をターゲットにしようとした場合、事前レンダリングサーバは、このエラーがスローされます。
SyntaxError: Unexpected token 'const'
http://localhost:3000/app.js:50 in eval
http://localhost:3000/app.js:50
http://localhost:3000/app.js:20 in __webpack_require__
http://localhost:3000/app.js:40
私は、これを動作させるために何らかの種類のポリフィルを含める必要があると思いますが、どのようなものを含めるべきか、どこに含めるべきかについての最初の考えはありません。
はvar webpack = require('webpack');
var path = require('path');
var rootDir = path.resolve();
module.exports =
{
target: 'node',
entry: rootDir + "/dist/client/app/bootstrap.js",
output: {
path: rootDir + "/dist/client", publicPath: '/', filename: "app.js",
pathinfo: true
},
devtool: 'eval',
resolve: {
root: rootDir + "/dist/client/app",
extensions: ['', '.js']
},
module: {
loaders: [
{
test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
}
]
}
};
そして助け場合、私のクライアントのTSconfig:私は私のWebPACKの設定を変更する場合は
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
"outDir": "../../dist/client",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true
},
"files": ["app/bootstrap.ts", "app/vendor.ts", "app/Window.ts", "tests/index.ts", "../../node_modules/typescript/lib/lib.es6.d.ts"]
}
更新
web
をターゲットに
はここに役立ちます場合は、私のWebPACKの設定ですnode
の代わりにserver.use(prerender.removeScriptTags());
をコメントアウトすると、リクエストは毎回プレレンダリングサーバーにヒットし、n oエラーはスローされますが、あらかじめレンダリングされているものはありません。以前よりも近くに見えるので、私は更新すると思った。
更新
プレレンダリングは角度コードを実行していないようです。私は私のindex.htmlで頭の中でスクリプトタグにwindow.prerenderReady = false
を設定し、これをtrueに設定しようとした場合、再び私のルートコンポーネントがインスタンス化されるとき、アウト事前レンダリングサーバ時間:
import { Component, OnInit } from '@angular/core'
@Component({
selector: 'my-app',
template: `
<div id="main"> all the things </div>
`
})
export class AppComponent implements OnInit
{
constructor(){}
ngOnInit()
{
// Prerender never executes this code before it times out
window.prerenderReady = true;
console.info('Prerender Ready');
}
}
はエラーが出て失敗し、ページのレンダリングを停止する(基礎となるレンダリングエンジン)PhantomJSを防止しているJavaScriptのそれらのように見えます:)します。 Mapにpolyfillを含めましたか? 'removeScriptTags'は、ページがレンダリングされた後でスクリプトタグを削除するだけで、レンダリングとは何の関係もないはずです。 –
webpackの設定で 'node'の代わりに 'web'を対象にすると、prerender es6エラーが発生しました。プレレンダリングサーバーは200を返しますが、角度コードは実行されません。 – MyCompassSpins
これに関する回答を得るのに役立つ他の詳細はありますか? – MyCompassSpins