grofit / aurelia-chart

A chart element for aurelia which is powered by chart js using html5 canvas.
MIT License
46 stars 25 forks source link

Looking for files in all the wrong places #26

Open jbnv opened 7 years ago

jbnv commented 7 years ago

Getting this error as I attempt to start up my application from the CLI:

Tracing aurelia-chart...
{ uid: 10,
  name: 'writeBundles',
  branch: false,
  error:
   { [Error: ENOENT: no such file or directory, open '/Users/mac/Projects/SongChartAurelia2/src/observers/model-observer.js']
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/mac/Projects/SongChartAurelia2/src/observers/model-observer.js',
     moduleTree: [ 'aurelia-chart' ],
     fileName: '/Users/mac/Projects/SongChartAurelia2/node_modules/aurelia-chart/dist/commonjs/index.js' },
  duration: [ 217, 485490417 ],
  time: 1481168967221 }

Aurelia is trying to find observers/model-observer.js in the application's root src directory, not the one for aurelia-chart. I added both aurelia-chart and chart.js through NPM. How can I resolve this problem?

grofit commented 7 years ago

It could be related to #21 #25, it seems depending on how you are consuming it there could be problems, the "core" logic in this plugin is sound, and has been since inception, almost all issues that plague it are down to the tooling around consuming modules so I have said in previous issues I don't have the capacity currently to fix it as the package.json main is hooked up to the right file so it should just work.

Hopefully someone can do a PR who knows the current tooling and approaches for Aurelia and then everyone can be happy until the next tooling change occurs :(

One other thing to mention is that you should load these plugins up as a plugin not a feature which some people use as a hack around, you may also need to consult the CLI docs to see if you need to add any custom properties to your package.json to imply what should be bundled.

jbnv commented 7 years ago

I'm at my day job right now and the project is a personal project, so I can't look into it further at the moment but will do so later. I am pretty sure that I am loading it as a plugin, but I will double-check.

jbnv commented 7 years ago

I set my aurelia.json per hozn's post in #25. Now my code compiles and runs at the command line, but throws undefined 'exports' on the first line of the code block below. Is this one of the variations of aurelia-chart?

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.configure = configure;

var _observersModelObserver = require("./observers/model-observer");

function configure(aurelia) {
    aurelia.globalResources("./elements/chart-element", "./attributes/chart-attribute");

    aurelia.container.registerTransient(_observersModelObserver.ModelObserver);
}
jbnv commented 7 years ago

Changed the code in aurelia.json to this:

          {
            "name": "chart.js",
            "path": "../node_modules/chart.js/dist",
            "main": "Chart.min"
          },
          {
            "name": "aurelia-chart",
            "path": "../node_modules/aurelia-chart/dist/amd",
            "main": "index"
          },

Now I'm getting the h.load error when I include .plugin('aurelia-chart').

grofit commented 7 years ago

Do they still have a plugins skeleton app? as it may be worth someone just grabbing that, putting these files in there and building off that, as so far 99% of the problems I receive are just trying to load the plugin in, there is rarely a problem once the plugin has been successfully loaded.

jbnv commented 7 years ago

Yes. You can generate one with the new Aurelia CLI.

jbnv commented 7 years ago

I created a shell application with the modifications and uploaded it to GitHub. The first commit is the unmodified shell application; the second commit are the changes that trigger the bug.

grofit commented 7 years ago

is it the package.json changes or the aurelia.json changes which primarily cause it? or is it just when both are there?

obust commented 7 years ago

With this aurelia.json config

          {
            "name": "chart.js",
            "path": "../node_modules/chart.js/dist",
            "main": "Chart.min"
          },
          {
            "name": "aurelia-chart",
            "path": "../node_modules/aurelia-chart/dist/amd",
            "main": "index",
            "resources": [
              "elements/chart-element.js",
              "elements/chart-element.html",
              "attributes/chart-attribute.js"
            ]
          },

The aurelia-cli can run the app, but the console outputs two errors: Uncaught Error: Mismatched anonymous define() module: function (exports, _aureliaFramework, _observersModelObserver, _chartJs)

Each one is caused respectively by elements/chart-element.js and attributes/chart-attribute.js (aka if i dont load these resources, i don't get the error but i can't use the package...)

This is highly related to jbnv's comment