Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

socket.io #525

Closed
guybedford opened this issue Aug 17, 2015 · 12 comments
Closed

socket.io #525

guybedford opened this issue Aug 17, 2015 · 12 comments

Comments

@guybedford
Copy link
Member

Socket.io has the following issues:

  1. We need to separately install jspm install github:rase-/node-XMLHttpRequest@add/ssl-support -o "{registry:'npm'}" as it needs a GitHub dependency for npm (this is explained in the warning on install)
  2. socket.io itself does a require to socket.io-client/package where the intention is to load the package.json. This can be fixed with a map on install - jspm install npm:socket.io -o "{map:{'socket.io-client/package':'socket.io-client/package.json!'}}" followed by a jspm install json.

This then gets us to the current error:

Uncaught TypeError: require.resolve is not a function(anonymous function) @ index.js:14(anonymous function) @ index.js:213__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030getModule @ system.src.js:1998(anonymous function) @ system.src.js:2034(anonymous function) @ index.js:2(anonymous function) @ index.js:4__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030getModule @ system.src.js:1998(anonymous function) @ system.src.js:2034(anonymous function) @ [email protected]:1(anonymous function) @ [email protected]:2__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030link @ system.src.js:1873Promise.all.then.normalizedDeps.execute @ system.src.js:2241doDynamicExecute @ system.src.js:715link @ system.src.js:916doLink @ system.src.js:569updateLinkSetOnLoad @ system.src.js:617(anonymous function) @ system.src.js:430
system.src.js:1237 Uncaught Uncaught TypeError: require.resolve is not a function
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]/lib/index.js__exec @ system.src.js:1237load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030getModule @ system.src.js:1998(anonymous function) @ system.src.js:2034(anonymous function) @ index.js:2(anonymous function) @ index.js:4__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030getModule @ system.src.js:1998(anonymous function) @ system.src.js:2034(anonymous function) @ [email protected]:1(anonymous function) @ [email protected]:2__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030link @ system.src.js:1873Promise.all.then.normalizedDeps.execute @ system.src.js:2241doDynamicExecute @ system.src.js:715link @ system.src.js:916doLink @ system.src.js:569updateLinkSetOnLoad @ system.src.js:617(anonymous function) @ system.src.js:430
system.src.js:1237 Uncaught Uncaught Uncaught TypeError: require.resolve is not a function
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]/lib/index.js
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]/index.js__exec @ system.src.js:1237load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030getModule @ system.src.js:1998(anonymous function) @ system.src.js:2034(anonymous function) @ [email protected]:1(anonymous function) @ [email protected]:2__exec @ system.src.js:1232load.metadata.execute @ system.src.js:2647linkDynamicModule @ system.src.js:2030link @ system.src.js:1873Promise.all.then.normalizedDeps.execute @ system.src.js:2241doDynamicExecute @ system.src.js:715link @ system.src.js:916doLink @ system.src.js:569updateLinkSetOnLoad @ system.src.js:617(anonymous function) @ system.src.js:430
test.html:1 Uncaught (in promise) Uncaught Uncaught Uncaught TypeError: require.resolve is not a function
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]/lib/index.js
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]/index.js
    Evaluating file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]
    Error loading file:///Users/guybedford/Projects/jspm-cli/sandbox/jspm_packages/npm/[email protected]

Which is a blocker as we don't currently support require.resolve for npm. We could support this though by replacing it with a System.normalizeSync(..., module.id), which is tracking in jspm/npm#88.

If we manually replace line 14 in jspm_packages/npm/[email protected]/lib.index.js from:

  var clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8');

to

  var clientSource = read(System.normalizeSync('socket.io-client/socket.io.js', module.uri), 'utf-8');

Then that seems to make socket.io work currently.

@salfield
Copy link
Contributor

I'm trying to use jspm beta.9 to install socket.io (on node). I've run into a couple of issues relating to the point above:

  1. jspm install github:rase-/node-XMLHttpRequest@add/ssl-support -o "{registry:'npm'}"

Gives me the following error:

err TypeError: Cannot read property 'hash' of undefined

This appears to be due to the url encoding of "/" in the version string in "package-name.js", while the package version information returned from registry.load appears not to be not url-encoded. Removing the url encoding of slash allows the package to install - but I assume you url encode these elements for a reason? In any case there appears to be bug here.

  1. jspm install socket.io, gives the following error:

err Error on locate for github:component/global/archive/v2.0.1.tar.gz

GitHub packages must be of the form owner/repo

This is caused by the has-cors package, whose package.json includes:

"dependencies": { "global": "https://github.com/component/global/archive/v2.0.1.tar.gz" }

I'm assuming this is fixable with a package override for has-cors? Will try to do that.

@guybedford
Copy link
Member Author

Both of the above sound like simple jspm bugs to fix actually, I will see if I can take a look at this later on this week.

@salfield
Copy link
Contributor

Great, thanks!

@guybedford
Copy link
Member Author

I've just tested this and jspm install npm:socket.io works fine for me actually in the latest 0.16 and 0.17 versions. Perhaps check this again on the latest versions of jspm and let me know if you're still getting the issues?

@salfield
Copy link
Contributor

salfield commented Mar 8, 2016

Yes, socket.io now installs correctly. Both issues were solved by overrides - so I'd suggest that the original problems haven't been solved.

The first issue was originally caused by the override for the old version of engine.io-client. The new version uses "xmlhttprequest-ssl" from npm.

The second issue is solved by my commits to the registry which ensure a new enough version of ws which uses an upgraded version of has-cors.

fyi - jspm install github:rase-/node-XMLHttpRequest@add/ssl-support -o "{registry:'npm'}", still fails for me on 0.17.0-beta9. Will now test with the latest version of 0.17.

Also, though socket.io installs it will not run, without using my fork at:

https://github.com/salfield/socket.io

I don't see this being resolved without a solution to:

jspm/npm#88

&

socketio/socket.io#2463

@guybedford
Copy link
Member Author

I just looked into these again and the second issue is specifically on has-cors 1.0.3 and not 1.1.0. I managed to track that down to a fix in jspm/npm@9d40917.

I must have been running on jspm 0.16 by mistake actually as the first issue is definitely still there, but let's continue to track this at jspm/jspm-cli#1571.

In terms of the remaining issues to get socket.io running:

  • salfield/socket.io@960bf89 is possible to substitute with a Node-specific map override. Something like:
    "map": { "socket.io-client": { "node": "@empty" } }
    note that these object maps are only supported in jspm 0.17 though.
  • For the require.resolve case, I've actually gone ahead and implemented this in SystemJS in systemjs/systemjs@5c51a53 (although not yet with build support). This should be released soon.

@salfield
Copy link
Contributor

salfield commented Mar 8, 2016

Wow, thanks so much for this :-) I'll try and move back to socketio/socket.io as soon as you release the new build. Seems like you have solutions for both my problems with respect to running socket.io.

I'll submit to the registry as soon as I know socket.io is running correctly with the above override. Incidentally, this problem is caused by a combination of:
a) the superfluous import of socket.io-client to socket.io, and
b) the fact that there is a different main function in socket.io-client package.json, which causes jspm to import the built socket.io.js rather than ./lib/index.

@salfield
Copy link
Contributor

For some reason in jspm beta.11 this doesn't seem to work for me. I've tried both:

"map": { "socket.io-client": { "node": "@empty" } }

and

"map": { "socket.io-client": "@empty" }

My package.json file has the following entry:

"npm:[email protected]": { "map": { "socket.io-client/package": "socket.io-client/package.json", "socket.io-client": { "node": "@empty" } } },

However, I still get the error caused by the import socket.io-client! Quite strange and I feel like I must be missing something obvious.

@guybedford
Copy link
Member Author

@salfield yes there is a bug with these maps in jspm 0.17 tracked in jspm/npm#129.

@salfield
Copy link
Contributor

Great, thanks for letting me know.

@guybedford
Copy link
Member Author

From what I can tell jspm install socket.io seems to be working ok in jspm 0.17, but please let me know if there are any issues here.

@salfield
Copy link
Contributor

salfield commented Apr 4, 2016

The above issue didn't stop socket.io from installing, only from running. I'm pretty sure the above overrides are required to run socket.io under jspm. Are the node specific overrides fixed in the latest beta? If so, it should install and run with the above overrides, which I'm happy to submit to the jspm registry after testing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants