These are chat archives for systemjs/systemjs

21st
Jan 2015
Ben Monro
@benmonro
Jan 21 2015 16:29 UTC

Hi All, I'm kind of a noob w/ SystemJS. I'm using it in Node and I'm trying to understand how to get it to understand my require statements properly. Any time I call System.import on a file that has a require that is in node_modules, I get an error that looks like this:

{ [Error: Error loading "jquery" at file:/Users/BenMonro/Desktop/Code/product/blerchy/node_modules/jquery.js
Error loading "jquery" from "blah" at file:/Users/BenMonro/Desktop/Code/product/blerchy/blah.js
ENOENT, open '/Users/BenMonro/Desktop/Code/product/blerchy/node_modules/jquery.js']
  errno: -2,
  code: 'ENOENT',
  path: '/Users/BenMonro/Desktop/Code/product/blerchy/node_modules/jquery.js' }

What am I doing wrong?

Guy Bedford
@guybedford
Jan 21 2015 16:29 UTC
@benmonro SystemJS doesn't use the node_modules resolution process
when it sees a require to require('jquery'), it will look for jquery.js in the base folder by default
this is because it doesn't rely on checking the package.jsons down the tree etc
rather, to load node modules, this is what jspm is designed to enable
when installing npm modules through jspm, SystemJS is configured to know where to load them properly
does that make some sense?
Ben Monro
@benmonro
Jan 21 2015 16:32 UTC
i see. yes a bit. I saw a talk on jspm at JSConf back in may. so does this mean I have to re-add all of my dependencies using jspm?
Guy Bedford
@guybedford
Jan 21 2015 16:32 UTC
yes exactly
Ben Monro
@benmonro
Jan 21 2015 16:32 UTC
and is there anything special I need to do w/ SystemJS to get it to use jspm? or just simply doing jspm init in my project is enough?
Guy Bedford
@guybedford
Jan 21 2015 16:33 UTC
it then works very smilarly to like npm
jspm comes with SystemJS by default
and will install it to 'jspm_packages/system.js'
Ben Monro
@benmonro
Jan 21 2015 16:33 UTC
oh... ok should i npm uninstall systemjs then?
Guy Bedford
@guybedford
Jan 21 2015 16:34 UTC
it shouldn't matter, but yes you won't need that version
Ben Monro
@benmonro
Jan 21 2015 16:34 UTC
alright, thanks, i'll give it a whirl, thanks!
Guy Bedford
@guybedford
Jan 21 2015 16:34 UTC
jspm has a node dependency on SystemJS as well too
sure, hope it works out ok
information on rough edges is always welcome
Ben Monro
@benmonro
Jan 21 2015 16:34 UTC
I'll report back! :)
Guy Bedford
@guybedford
Jan 21 2015 16:34 UTC
thanks
Ben Monro
@benmonro
Jan 21 2015 16:35 UTC
oh, I just realized that Talk I saw at JSConf was you! Great talk! :)
Guy Bedford
@guybedford
Jan 21 2015 16:36 UTC
ha, sure thanks!
Ben Monro
@benmonro
Jan 21 2015 16:47 UTC
hmm, so when I execute node index.js i can't seem to get it to recognize System.
Guy Bedford
@guybedford
Jan 21 2015 16:48 UTC
how are you running System?
Ben Monro
@benmonro
Jan 21 2015 16:48 UTC
i've tried doing var System = require('systemjs'); and ``import System from 'system
here's my little sample code:

var code = 'function() {/*what goes here? */ System.import("lib/blah").then(function(m){m.blah();}).catch(console.error);}';
var fn = eval("(" + code + ")");
fn();
Guy Bedford
@guybedford
Jan 21 2015 16:49 UTC
right
so you want to use SystemJS in Node, to load npm modules?
Ben Monro
@benmonro
Jan 21 2015 16:50 UTC
yes
Guy Bedford
@guybedford
Jan 21 2015 16:50 UTC
ok, at the moment jspm's focus is very much on the browser
some npm modules will work fine
but it is not supported strongly in Node yet
Ben Monro
@benmonro
Jan 21 2015 16:51 UTC
well my litlte hello world here is just using jquery
Guy Bedford
@guybedford
Jan 21 2015 16:51 UTC
are you trying to run jQuery in Node?
Ben Monro
@benmonro
Jan 21 2015 16:51 UTC
actually this is mainly for our mocha tests
most of our actual code will be in the browser
Guy Bedford
@guybedford
Jan 21 2015 16:51 UTC
sure
Ben Monro
@benmonro
Jan 21 2015 16:51 UTC
just as a sample, it really could be anything, i just want to see it load something
Guy Bedford
@guybedford
Jan 21 2015 16:51 UTC
so jspm run is designed to run code on the server
jspm run test
where test.js
contains
Ben Monro
@benmonro
Jan 21 2015 16:52 UTC
even if its an error message saying jquery requires window :)
Guy Bedford
@guybedford
Jan 21 2015 16:52 UTC
import jquery from 'jquery';
jspm install npm:jquery
that's a basic server example
then you can load test.js in the browser with the browser workflow too
you can also do require('jspm').import('test')
Ben Monro
@benmonro
Jan 21 2015 16:54 UTC
ok i see. i think that should be enough to get our tests going, i'll try it out in our app now
thanks for your help!
Guy Bedford
@guybedford
Jan 21 2015 16:55 UTC
sure, good luck with it
Ben Monro
@benmonro
Jan 21 2015 16:55 UTC
thx. oh 1 last question. when i run mocha using jspm is it just jspm run mocha?
Guy Bedford
@guybedford
Jan 21 2015 16:55 UTC
server npm requires will hit issues, so don't expect them to all work out
Ben Monro
@benmonro
Jan 21 2015 16:55 UTC
that's fine its just for our mocha tests at this point.
Guy Bedford
@guybedford
Jan 21 2015 16:56 UTC
I don't think mocha will run in jspm on the server
I'm getting this error - Module npm:mocha@2.1.0/mocha not declared as a dependency.
Ben Monro
@benmonro
Jan 21 2015 16:57 UTC
dang
Guy Bedford
@guybedford
Jan 21 2015 16:57 UTC
it can be made to work
but the process is quite involves
I could probably get it to work within an hour
but it's hard to find that hour
as I say though, we're focusing on the browser loading for now
Ben Monro
@benmonro
Jan 21 2015 16:58 UTC
heh. that means it'd probably take me 10 hours :(
yeah understood
Guy Bedford
@guybedford
Jan 21 2015 16:58 UTC
yeah overrides like that are tough to do, I wish more people could be able to help with it, but its a learning curve
mocha works in the browser fine with jspm
Ben Monro
@benmonro
Jan 21 2015 16:59 UTC
hmm. ok maybe i'll look at that as an option.
Guy Bedford
@guybedford
Jan 21 2015 16:59 UTC
actually, let me check again - I'm running on a dev branch actually
Ben Monro
@benmonro
Jan 21 2015 16:59 UTC
k
Guy Bedford
@guybedford
Jan 21 2015 17:03 UTC
So if you do mocha 1.21.5, I think that might have a better chance of working
jspm install npm:mocha@^1.21.5
it was configured for the browser a few months ago
I don't know how it will behave on the server though
wouldn't hold my breath
would definitely advise npm for server as I say
Ben Monro
@benmonro
Jan 21 2015 17:04 UTC
that's fine, we're building a client framework, so if i need to move the tests to a browser that shoudl be fine
Guy Bedford
@guybedford
Jan 21 2015 17:04 UTC
the above will work in the browser fine
we can get mocha 2 configured soon
Ben Monro
@benmonro
Jan 21 2015 17:05 UTC
cool
Ben Monro
@benmonro
Jan 21 2015 21:52 UTC
ok I have another question. I have a module which is part of my browserify bundle. the code for that is already in the page, but when I hit System.import("lib/helpers") it's attempting to fetch it from the server (which it wont find since its part of the bundle and not served up). Is there any way to tell SystemJS that whenever System.import("lib/helpers") is called to just return 'require('./helpers')' or something like that?