1

I created a new aurelia project and installed gojs via npm. I added gojs to the aurelia.json dependencies and, without adding any gojs code, just tried to build the project. The build worked fine and gojs went to the vendor-bundle.js The issue is, when I run the project, I get an error from gojs. When I remove the gojs dependency in aurelia.json, the project runs just fine but adding it back always throws the same error located below. Please help.

Uncaught Error: Mismatched anonymous define() module: [object Object]
http://requirejs.org/docs/errors.html#mismatch
   at makeError (vendor-bundle.js:11531)
   at intakeDefines (vendor-bundle.js:12617)
   at vendor-bundle.js:12815
makeError @ vendor-bundle.js:11531
intakeDefines @ vendor-bundle.js:12617
(anonymous) @ vendor-bundle.js:12815
setTimeout (async)
req.nextTick @ vendor-bundle.js:13178
localRequire @ vendor-bundle.js:12812
requirejs @ vendor-bundle.js:13160
(anonymous) @ vendor-bundle.js:13199
(anonymous) @ vendor-bundle.js:13508
seroth
  • 581
  • 1
  • 9
  • 26

2 Answers2

3

To clear up some confusion here, you're talking about declaring the dependency in aurelia.json which implies you're using aurelia-cli in conjunction with the requirejs loader.

jmdavid's answer mentions webpack which is a different beast altogether. You don't declare dependencies in aurelia.json there; webpack resolves those by itself via the imports it finds in your entry file. I would actually recommend switching to webpack for various reasons; the fact that it would fix the error is just one of them.

The error is likely caused by the go.js module being loaded twice. The error throws on the second load; it should still work regardless of the error. You can't make the error go away in any straightforward manner with requirejs, this is due to how the go.js release is packed.

The only error-free way to load go.js here would be to do so before requirejs is loaded. In aurelia.json:

"node_modules/gojs/release/go.js",
"node_modules/requirejs/require.js"

And no need to import it then either, it will just be available globally.

Fred Kleuver
  • 7,797
  • 2
  • 27
  • 38
  • This worked great. Thanks for explaining what the error was. – seroth Mar 24 '18 at 21:27
  • Any idea why the gojs module would be loaded twice? Is this a bug in the go.js library? – Simon Sarris Mar 26 '18 at 14:41
  • @SimonSarris Since you're a go.js dev, I took a look and found that it actually chokes straight away on this bit: `(window.go = ca, window.define(ca));`. It's not being defined twice; rather, it's being set globally once, and attempted to be defined but that call simply fails. You need to remove that `window.ca = ca` because it beats the purpose of asynchronous module loading and change the define call to `window.define('go', ca)`. That will allow people to do something like `import * as go from "go"` and it won't be loaded until *that* call happens in the user's code. – Fred Kleuver Mar 26 '18 at 16:44
  • Actually the script will be loaded anyway because, well, the library's release format just isn't module-loader friendly. If this is something you're looking to improve, I recommend you take a look at any of aurelia's core packages and look at the `dist` folders. A separate release file per module loader format, all automatically generated. It's neat and it's something I think is a shame libraries like go.js and gsap don't do it that way. – Fred Kleuver Mar 26 '18 at 16:51
  • @FredKleuver Thanks for the advice! – Simon Sarris Mar 26 '18 at 20:46
2

Probably the versions are oudated on fedoranimus github (https://github.com/fedoranimus/aurelia-gojs).

I made it work by creating a new project with the cli (au new) with webpack and typescript, then npm installed gojs (version "^1.8.15"), then copied relevant code from fedoranimus.

jmdavid
  • 58
  • 5
  • I created a new project (au new) and npm installed gojs, added gojs to the aurelia.json and au build and the error still happens. Did you add gojs to the aurelia.json file? – seroth Mar 23 '18 at 16:22
  • @jmdavid he didn't mention fedoranimus' github anywhere so I don't even think that's relevant here. The versions make no difference either – Fred Kleuver Mar 24 '18 at 03:45
  • Looks like using webpack was the difference between your version and mine. I use requirejs and that was where the issue originates. Doing what @FredKleuver said solved the issue. – seroth Mar 24 '18 at 21:29
  • FYI: The dependencies have been updated. But yes, OP was seeing an issue with requirejs. Hopefully the GoJS team will give us a named define in a future release. – Fedoranimus Mar 30 '18 at 13:38