Webpack attempts to require Chart.js as 'chart'
Module not found: Error: Cannot resolve module 'chart' in /node_modules/angular-chart.js/dist
resolve module chart in /node_modules/angular-chart.js/dist
looking for modules in /node_modules
/node_modules/chart doesn't exist (module as directory)
resolve 'file' chart in /node_modules
Changing the AMD register to use chart.js instead of chart resolves the issue:
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['angular', 'chart.js'], factory);
Or using webpack to create an alias also resolves the issue:
config.resolve.alias = {
'chart': require.resolve('chart.js')
}
Is this expected behaviour?
This behavior was introduced in the last update to fix a requirejs issue
Yes sorry about that, as @jantimon fixing AMD broke webpack... AMD couldn't be fixed with configuration, whereas webpack does. I should have bumped to major version though but it's a bit too late now. I'm adding an example for webpack, and updating the readme.
Could we just switch the require calls? then it would work out of the box for Browserify and webpack (requirejs would still work with a configuration like it does now): hacked it together on my mobile do can't test it but it should do:
if (typeof exports === 'object') { // Node/CommonJS module.exports = factory(require('angular'), require('chart.js')); } else if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['angular', 'chart'], factory); } else { // Browser globals factory(angular, Chart); } }
Ok I'll give it a try.
Yes that totally worked.
I am still having this issue with webpack and had to add an alias in webpack for chart.js
I had to do:
resolve: { alias: {'chart.js': require.resolve('chartjs')} },
Using Webpack 2 I had this error:
Module not found: Error: Can't resolve 'chart' in '/var/www/my-project/node_modules/angular-chart.js/dist'
@ /var/www/my-project/~/angular-chart.js/dist/angular-chart.js 22:4-41
@ multi vendor
I fixed this using:
module.exports = {
resolve: {
alias: { 'chart': require.resolve('chart.js') }
},
...
}
This is still not working as it comes. But, the alias on the resolve section on webpack works in Webpack 3.8.1.