# CanJS AMD Build

**URL:** <https://forums.bitovi.com/t/canjs-amd-build/515>\
**Category:** CanJS\
**Created:** [December 22, 2016, 5:32pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515 "2016-12-22T17:32:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![roemhildtg](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/roemhildtg/32/103_2.png) [@roemhildtg](https://forums.bitovi.com/u/roemhildtg)\
**Post date:** [December 22, 2016, 5:32pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/1 "2016-12-22T17:32:24Z")

</div>

I’m trying to make an AMD build of canjs 3.0 by modifying the build script. Here’s what I’ve got so far:

```javascript
var stealTools = require('steal-tools');
var globalJS = require('steal-tools/lib/build/helpers/global').js;
var amdJS = require('steal-tools/lib/build/helpers/amd');
var baseNormalize = globalJS.normalize();
stealTools.export({
    system: {
        config: __dirname + '/package.json!npm',
        main: 'can/all'
    },
    options: {
        useNormalizedDependencies: false,
        verbose: true
    },
    outputs: {
        'all': {
            modules: ['can/all'],
            format: 'amd',
            dest: amdJS.dest({}, __dirname + '/dist/amd'),
            useNormalizedDependencies: true,
            normalize: function (depName, depLoad, curName, curLoad, loader) {
                return baseNormalize.call(this, depName, depLoad, curName, curLoad, loader, true);
            },
            // ignore jquery
            ignore: [function (name) {
                if (name.indexOf('jquery') === 0 || name.indexOf('kefir') === 0) {
                    return true;
                } else {
                    return false;
                }
            }],
            removeDevelopmentCode: false
        }
    }
}).catch(function (e) {

    setTimeout(function () {
        throw e;
    }, 1);

});

```

This isn’t working at the moment though, so I’ve also tried using the `+amd` helper in steal-tools. This results in a call stack exceeded error. So I’m not sure what’s going on here.

---

<div class="post-metadata">

**Author:** ![phillipskevin](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/phillipskevin/32/102_2.png) [@phillipskevin](https://forums.bitovi.com/u/phillipskevin)\
**Post date:** [December 22, 2016, 5:51pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/2 "2016-12-22T17:51:50Z")

</div>

You probably also need to update it to use the AMD version of normalize instead of `return baseNormalize.call(`. I’m not sure this will solve your problem though.

---

<div class="post-metadata">

**Author:** ![roemhildtg](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/roemhildtg/32/103_2.png) [@roemhildtg](https://forums.bitovi.com/u/roemhildtg)\
**Post date:** [December 22, 2016, 7:13pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/3 "2016-12-22T19:13:05Z")

</div>

I tried setting that to the amd’s normalize, but there were still errors. From what I read in the docs, using the `+amd` tag should set up the output object to use the correct functions, but it results in this error message…do you know why this would happen? A steal-tools bug?

```auto
C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs>node build
  added helpers: amd
OPENING: can/all
-local+ npm
..........
-local+ can-fixture@1.0.11#helpers/getid
OUTPUT: +amd
Transpiling...
Output Modules:
+ can@3.3.0#all
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\all.js
Transpiling...
Output Modules:
+ can@3.3.0#can
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\can.js
Transpiling...
Output Modules:
+ can@3.3.0#ecosystem
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\ecosystem.js
Potentially unhandled rejection [1] RangeError: Maximum call stack size exceeded

    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5

```

Here’s the script to produce this error:

```javascript
var stealTools = require('steal-tools');
stealTools.export({
    system: {
        config: __dirname + '/package.json!npm',
        main: 'can/all'
    },
    options: {
        useNormalizedDependencies: false,
        verbose: true
    },
    outputs: {
        '+amd': {
            modules: ['can/all'],
            format: 'amd',
            useNormalizedDependencies: true,
            // ignore jquery
            ignore: [function (name) {
                if (name.indexOf('jquery') === 0 || name.indexOf('kefir') === 0) {
                    return true;
                } else {
                    return false;
                }
            }],
            removeDevelopmentCode: false
        }
    }
}).catch(function (e) {

    setTimeout(function () {
        throw e;
    }, 1);

});

```

---

<div class="post-metadata">

**Author:** ![chasen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/chasen/32/402_2.png) [@chasen](https://forums.bitovi.com/u/chasen)\
**Post date:** [January 11, 2017, 8:19pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/4 "2017-01-11T20:19:48Z")

</div>

Hey @roemhildtg, did you figure out the issue or a workaround?

---

<div class="post-metadata">

**Author:** ![roemhildtg](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/roemhildtg/32/103_2.png) [@roemhildtg](https://forums.bitovi.com/u/roemhildtg)\
**Post date:** [January 12, 2017, 2:23pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/5 "2017-01-12T14:23:27Z")

</div>

@chasen I didn’t figure this out yet. In the meantime I’m just using steal to load my canjs app.

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [January 12, 2017, 7:50pm UTC](https://forums.bitovi.com/t/canjs-amd-build/515/6 "2017-01-12T19:50:27Z")

</div>

@roemhildtg Would you mind filing a bug in steal-tools on that. I don’t see anything in your code that should trigger a maximum call stack.

---

<div class="post-metadata">

**Author:** ![roemhildtg](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/roemhildtg/32/103_2.png) [@roemhildtg](https://forums.bitovi.com/u/roemhildtg)\
**Post date:** [January 13, 2017, 1:08am UTC](https://forums.bitovi.com/t/canjs-amd-build/515/7 "2017-01-13T01:08:46Z")

</div>

@matthewp, sure no problem. Here’s the issue I created: [https://github.com/stealjs/steal-tools/issues/582](https://github.com/stealjs/steal-tools/issues/582)

---

<div class="post-metadata">

**Author:** ![Nothing\_New](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/nothing_new/32/206_2.png) [@Nothing\_New](https://forums.bitovi.com/u/Nothing_New)\
**Post date:** [January 26, 2017, 6:40am UTC](https://forums.bitovi.com/t/canjs-amd-build/515/8 "2017-01-26T06:40:29Z")

</div>

Would that be cause by a circular dependency tree?
