Search code examples
aureliagojs

gojs and Aurelia mismatch error


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

Solution

  • 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.