Jasmine ReferenceError: require is not defined

2,254 views
Skip to first unread message

Lukasz Zablocki

unread,
Sep 19, 2016, 10:11:42 AM9/19/16
to Jasmine
My jasmine work good with cli but problem is display result in browser (ReferenceError: require is not defined). In my script i using require node function to load modules.

<!DOCTYPE html>
<html>

<head>
 
<meta charset="utf-8">
 
<title>Jasmine Spec Runner v2.4.1</title>

 
<link rel="shortcut icon" type="image/png" href="node_modules/jasmine-core/lib/jasmine-core/jasmine_favicon.png">
 
<link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">

 
<script src="/node_modules/systemjs/dist/system.js" type="text/javascript"></script>
 
<script>  
   
System.config({
        baseURL
: '/app'
   
});
     
System.import('app.component.spec')
   
.then(null, console.error.bind(console));
</script>

 
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
 
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
 
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
 
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>

 
<!-- include source files here... -->
 
<script src="server/scripts/auth.js"></script>

 
<!-- include spec files here... -->
 
<script src="spec/server/authSpec.js"></script>

</head>

<body>
</body>

</html>


Charles Hansen

unread,
Sep 19, 2016, 11:11:31 AM9/19/16
to jasmi...@googlegroups.com
'require' is only defined in node, not in the browser. To run jasmine in the browser with require, you will need to use something like webpack or browserify. I'm not sure which Jasmine runner you are using, but here are basic webpack instructions for gulp-jasmine-browser https://github.com/jasmine/gulp-jasmine-browser#usage-with-webpack

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+unsubscribe@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at https://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages