角度2:错误TS2307:找不到模块'socket.io-client' [英] Angular 2: error TS2307: Cannot find module 'socket.io-client'
问题描述
安装模块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
-Types.d.ts
socket.io-client (Directory)
- socket.io.js
- typings.d.ts
Angular 2 RC5
Angular 2 RC5
推荐答案
2018年更新
要在浏览器中正确使用socket.io,您需要同时安装socket.io客户端软件包及其类型:
Update 2018
To properly use socket.io in the browser you need to install both the socket.io client package and its typings:
npm i socket.io-client @types/socket.io-client
过时:
您缺少键入内容.
打开typings.d.ts
并添加
outdated:
You are missing typings.
Open typings.d.ts
and add
declare module 'socket.io-client' {
var e: any;
export = e;
}
您也可以尝试通过npm i @types/socket.io-client
为socket.io安装类型.我不知道是否有可用的输入.
You can also try to install typings for socket.io via npm i @types/socket.io-client
. I don't know if there are typings available, though.
这篇关于角度2:错误TS2307:找不到模块'socket.io-client'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!