var can = require(‘can’); (in Develop your application, about half way down the page)
All I get when I try to run it is a browser error that 'require is not a function.
wtf ???
I have run ‘npm install require --save’ and it is included in the node_modules in the subdir as expected.
‘npm run build’ does not complain so I have NO F** CLUE what is going on.
Help much appreciated.
I’m fairly experienced in the use of CanJS for complex applications but have not yet used steal/require/module loaders as my legacy technology restrictions make it very hard to integrate (js ‘files’ etc are in IDE binary blobs …) but I’m breaking out of the legacy into a trad file based setup, and smack into this.
Hey @ron.yuen, sorry you’ve run into this problem. I’ll take a look at that guide and see if there’s a problem. In the mean time you might want to check out the Quick Start and then Progressive Loading guides which were recently updated.
I have cut and paste into index.html,app.js,homepage.js,login.js etc and
IT ALL WORKS
But then I add
var can = require(“can”);
to app.js, run npm build and then run in the browser and it all falls over. ‘require is not a function’.
I have a require in node_modules courtesy of ‘npm install require – save’ I notice, however, that there is no ‘require.js’ which I kindof expected to see
Am I installing the correct ‘require’ ???
The node and npm installations were made a couple of days ago and are ABSOLUTELY clean, no prior history.
I’m running nginx / openresty as the http server
If I use the ‘import can from ‘can’;’ syntax instead of require then it all works and I can go on to use can.stache / templates etc as I’m used to
the mere presence of the require() in the source triggers a collapse, this is what Firefox has to say
@ron.yuen: do you have some multiline JS comment on your code (main.js) with “” inside?
I had a multiline comment linke the following, because i was trying different modules import methods (AMD and CommonJS):
/* import can from "can";
import $ from "jquery"
*/
When I removed them, and all start working correctly.
I don’t know if is a steal problem or not but… lot of time seraching other, more complex issues, and at the end was this “nut”.