2017-01-23 15 views
0

私はangle2でsocket.ioを使ってソケット通信を発信/受信するプロジェクトを作成しました。 JIT(またはnpm start)ではすべてがうまく動作しますが、ロールアップを介してコードをコンパイルしようとすると、プロダクション用のAOTとしてランチされません。動作しません。load socket.io with Angular 2 AOT

ノードのバージョン:6.9.4 NPMバージョン:3.10.6

typings.json

{ 
    "globalDependencies": { 
    "core-js": "registry:dt/core-js#0.0.0+20160725163759", 
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255", 
    "node": "registry:dt/node#7.0.0+20170110233017", 
    "socket.io-client": "registry:dt/socket.io-client#1.4.4+20161116080703" 
    }, 
    "ambientDependencies": { 
    "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#138ad74b9e8e6c08af7633964962835add4c91e2", 
    "socket-io-client": "github:DefinitelyTyped/DefinitelyTyped/socket.io-client/socket.io-client.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd", 
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654" 
    } 
} 

systemjs.config.js

map : {"socket.io-client": 'npm:socket.io-client'} 
packages : { "socket.io-client": { 
      main: './socket.io.js', 
      "defaultExtension": "js" 
     } } 

package.json: 「ソケット.io-client ":"^1.7.2 "

mycomponent.ts

import * as io from 'socket.io-client'; 
var url = 'http://localhost:4500'; 
export var socket = io(url); 

"node_modules/.binファイル/ NGC" -pのTSconfig-aot.jsonが正常に実行されますが "node_modules/.binファイル/ロールアップ" -cロールアップ-config.jsのは、エラーを与える:cannot call a namespace ('io')

の場合私はコンポーネントのインポート行を変更してimport io from socket.io-clientを設定してエラーが発生します。module 'socket.io-client' has no default export これはトラブルシューティングの2日目であり、他のフォーラムで試してみてくれたら嬉しいです。事前に

おかげで、 カピル

答えて

0

キープインポート:

import * as io from 'socket.io-client'; 

そしてrollup.jsにプラグインを追加します。

{ 
    name: 'replace io imports', 
    transform: code => ({ 
     code: code.replace(/import\s*\*\s*as\s*io/g, 'import io'), 
     map: { mappings: '' } 
    }) 
},