New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught TypeError: angular.module is not a function #2049
Comments
Listing other file sources, for quick test start // app.js
define([
'angular'
]
, function (angular) {
'use strict';
var app = angular.module('app', []);
return app;
}); <!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Angular Test</title>
</head>
<body>
angular test
<script src="assets/app.js"></script>
</body>
</html> |
Angular doesn't seem to support CommonJS. You'll need to shim it with
They did put in their changelog that they were supporting CommonJS, but I've always had this issue with the library. |
Ahh, you're using AMD. I'm not sure how that format works with Webpack. I'll see if I can get a working example for you. |
If it helps, you can have a look at a blogpost I wrote on working with Angular and Webpack. I definitely had a hard time getting Angular to load properly. They key ended up being something like: module: {
loaders: [
{ test: /[\/]angular\.js$/, loader: "exports?angular" }
]
},
resolve: {
alias: {
angular: __dirname + '/app/vendor/angular/angular'
}
} This works for us in files using AMD as well as those in ES6 module syntax. |
@mlent Your config snippet is working in AMD, thx! Just out of curiosity, why adding a |
@ace-han the The alias @mlent gives points directly to the raw angular.js script without the commonjs wrapping; The exports loader then exports the When you use angular without the alias it will try and use the Sorry if this doesn't make sense. English is my first language, I'm just better at javascript than words.. |
@danpantry for the part
Is this the default behaviour in AMD? I mean the As far as I know, in AMD below codes should work fine define(['dep1', 'dep2'], function(dep1, dep2){
// dep1, dep2 should be already fully loaded
dep1.doSth1();
dep2.doSth2();
})
require(['dep3', 'dep4'], function(dep3, dep4){
// dep3, dep4 should be already fully loaded
dep3.doSth3();
dep4.doSth4();
}) Do I understand well? Is webpack's AMD define(function ( require ) {
var isReady = false, foobar;
// note the inline require within our module definition
require(['foo', 'bar'], function (foo, bar) {
isReady = true;
foobar = foo() + bar();
});
// we can still return a module
return {
isReady: isReady,
foobar: foobar
};
}); |
The code you've got there is completely asynchronous. The function you pass to |
Thx @danpantry. Two more quick questions define(['angular'], function(angular){
// here angular is just a reference, might not be fully loaded
// Point_1
angular.module('app', []);
// other stuff...
})
|
Sure.
I'd recommend that unless you're bound to AMD (via requirejs) that you use CommonJS or ES6 modules and only fall back on asynchronous loading if you absolutely have to. It just makes code easier to read about. Recommended reading: http://requirejs.org/docs/start.html |
@danpantry Thx for the explanation! |
I feel this should be mentioned for anyone else who has found themselves here for the same reason, AMD stands for Asynchronous Module Definition. |
@mlent It works. just wonder the reason. will |
@danpantry
The solution does not work .
|
@danpantry I can use angular by @mlent's approach, I just can't use it with raven-js togher.So I think I installed angular properly. I mean it just are you using raven-js CommonJs way ?? like this
I output the result of |
@danpantry by the way, I rename |
My
webpack.config.js
as belowMy demo project looks like
if I enable
webpack.ResolverPlugin
, I will get below error when open index.html in the browserRunning
webpack
output(withwebpack.ResolverPlugin
or not) looks like below:Where have I done wrong?
Plz kindly help me out, thx.
The text was updated successfully, but these errors were encountered: