安装模块socket.io后
npm install socket.io --save
我有以下错误:
错误TS2307:找不到模块’socket.io-client’
进口
import * as io from 'socket.io-client';
systemjs.config.js
var map = { 'socket.io-client': 'node_modules/socket.io-client/socket.io.js' } var packages = { 'socket.io-client': { main: 'socket.io',format: 'cjs',defaultExtension: 'js' } }
的package.json
"dependencies": { "socket.io": "^1.4.8" }
typings.d.ts
/// <reference path="../socket.io-client/socket.io.js" /> declare module 'socket.io-client' { var e: any; export = e; }
socket.io-client(目录)
– socket.io.js
– typings.d.ts
Angular 2 RC5
更新2018年
要在浏览器中正确使用socket.io,您需要安装socket.io客户端软件包及其类型:
npm i socket.io-client @types/socket.io-client
过时的:
你缺少打字.
打开typings.d.ts并添加
declare module 'socket.io-client' { var e: any; export = e; }
您还可以尝试通过npm i @ types / socket.io-client为socket.io安装typings.不过,我不知道是否有可用的打字.