2016-10-07 2 views
1

新しいプロジェクトでionic2をアップグレードした後(ゼロから) socket.ioを使用できません。ionic2ロールアップビルド失敗:バンドルプロダクトが失敗しました:名前空間( 'io')を呼び出すことができません

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

...  

    this.socket = io(url); 
      .... 

ビルドに失敗しました:バンドルPRODに失敗しました:

typings install dt~socket.io-client --save --global 

エラー印刷と:それはすることで解決された( 'IO')以前のバージョンで

名前空間を呼び出すことはできません以下の構成:

[12:19:27] bundle prod failed: Cannot call a namespace ('io') 
[12:19:27] Error: Cannot call a namespace ('io') 
    at error (/*****************/node_modules/rollup/dist/rollup.js:5404:12) 
    at CallExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5837:5) 
    at /*****************/node_modules/rollup/dist/rollup.js:5149:50 
    at AssignmentExpression.eachChild (/*****************/node_modules/rollup/dist/rollup.js:5166:5) 
    at AssignmentExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5149:7) 
    at AssignmentExpression.bind (/*****************/node_modules/rollup/dist/rollup.js:5509:23) 
    at /*****************/node_modules/rollup/dist/rollup.js:5149:50 
    at ExpressionStatement.eachChild (/*****************/node_modules/rollup/dist/rollup.js:5166:5) 
    at ExpressionStatement.bind (/*****************/node_modules/rollup/dist/rollup.js:5149:7) 
    at BlockStatement.bind (/*****************/node_modules/rollup/dist/rollup.js:5615:9) 
Error running ionic app script "build": Error: Cannot call a namespace ('io') 

npm ERR! Linux 4.4.0-38-generic 
npm ERR! argv "/.nvm/versions/node/v6.7.0/bin/node" "/.nvm/versions/node/v6.7.0/lib/node_modules/npm/bin/npm-cli.js" "run-script" "build" 
npm ERR! node v6.7.0 
npm ERR! npm v3.10.3 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] build: `ionic-app-scripts build` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] build script 'ionic-app-scripts build'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  ionic-app-scripts build 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs ionic-hello-world 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls ionic-hello-world 
npm ERR! There is likely additional logging output above. 

....

package.json

{ 
... 
     "dependencies": { 
     "@ionic/storage": "^1.0.3", 
     "ionic-angular": "^2.0.0-rc.0", 
     "ionic-native": "^2.0.3", 
     "ionicons": "^3.0.0", 
     "socket.io-client": "^1.5.0" 
     }, 
     "devDependencies": { 
     "@ionic/app-scripts": "latest", 
     "typescript": "^2.0.3" 
     }, 
... 
     "cordovaPlugins": [ 
     "cordova-plugin-device", 
     "cordova-plugin-console", 
     "cordova-plugin-whitelist", 
     "cordova-plugin-splashscreen", 
     "cordova-plugin-statusbar", 
     "ionic-plugin-keyboard" 
     ], 
     "cordovaPlatforms": [] 
    } 

typings.json

{ 
    "globalDependencies": { 
    "socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654" 
    } 
} 

システム情報

  • コルドバCLI:6.3.1
  • イオンFrameworkのバージョン:2.0.0-beta.11
  • イオンCLIバージョン:2.1.0-beta.3
  • イオンのApp Libのバージョン:2.1.0-beta.1
  • OS:ディストリビューターID: Ubuntuの説明:Ubuntuの16.04.1 LTS
  • ノードバージョン:v6.7.0

答えて

0

ソリューション:なしワイルドカードのインポート... 'socket.io-クライアント' から

輸入IO;

代わり

インポート*として「socket.io-クライアントの

1

構文

import io from 'socket.io-client' 

..is標準ではない、あなたが持っているだろうランタイムエラーからのIO:

import * as io from 'socket.io-client'の構文を維持し、Typescript cast ioをanyと指定してデフォルトのメソッドを呼び出します。

var ioFunc = (io as any).default ? (io as any).default : io; 
    this.socket = ioFunc(url); 
関連する問題