如何使用 systemjs 导入 socket.io-client?
How to import socket.io-client using systemjs?
如何导入独立 socket.io 客户端?我使用 system.js 作为模块加载器,我用 typescript 编写代码。
在我的打字稿文件中,我有以下导入语句。
import * as io from 'socket.io-client';
system.js 的配置如下所示。
System.config({
map: {
rxjs: 'node_modules/rxjs',
'socket.io-client': 'node_modules/socket.io-client'
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
rxjs: {defaultExtension: 'js'},
'socket.io-client': {defaultExtension: 'js'}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
在我的浏览器中出现此错误。
angular2-polyfills.js:126 GET
http://localhost:3000/node_modules/socket.io-client/ 404 (Not Found)
我需要做什么才能加载这个模块?
尝试指定 socket.io.js 的完整路径,如下所示
System.config({
map: {
rxjs: 'node_modules/rxjs',
'socket.io-client': 'node_modules/socket.io-client/socket.io.js'
},
...
System.config({
map: {
...
"socket.io-client": "npm:socket.io-client/dist"
},
...
packages: {
...
"socket.io-client": {"main": "./socket.io.js"}
}
});
如何导入独立 socket.io 客户端?我使用 system.js 作为模块加载器,我用 typescript 编写代码。
在我的打字稿文件中,我有以下导入语句。
import * as io from 'socket.io-client';
system.js 的配置如下所示。
System.config({
map: {
rxjs: 'node_modules/rxjs',
'socket.io-client': 'node_modules/socket.io-client'
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
rxjs: {defaultExtension: 'js'},
'socket.io-client': {defaultExtension: 'js'}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
在我的浏览器中出现此错误。
angular2-polyfills.js:126 GET http://localhost:3000/node_modules/socket.io-client/ 404 (Not Found)
我需要做什么才能加载这个模块?
尝试指定 socket.io.js 的完整路径,如下所示
System.config({
map: {
rxjs: 'node_modules/rxjs',
'socket.io-client': 'node_modules/socket.io-client/socket.io.js'
},
...
System.config({
map: {
...
"socket.io-client": "npm:socket.io-client/dist"
},
...
packages: {
...
"socket.io-client": {"main": "./socket.io.js"}
}
});