jods4/aurelia-webpack-build

Value Converter not found at runtime

gregoryagu opened this issue · 4 comments

I have a value converter called DateFormat.

.globalResources(
        [
            PLATFORM.moduleName('./core/converters/date-format'),
          ])

I have verified that this is found and included in the build file.


/***/ "core/converters/date-format":
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_moment__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_moment___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_moment__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DateFormatValueConverter", function() { return DateFormatValueConverter; });

var DateFormatValueConverter = (function () {
    function DateFormatValueConverter() {
    }
    DateFormatValueConverter.prototype.toView = function (value) {
        if (value) {
            //A workaround for null dates, which gets set to an actual date.
            if (typeof value.getMonth === 'function') {
                if (value.getTime() === 0) {
                    return "";
                }
                return moment(value).format('MMM Do, YYYY');
            }
            else {
                return "";
            }
        }
    };
    return DateFormatValueConverter;
}());

However, at runtime I get this error:

Unable to find module with ID: ./core/converters/date-format

This is how it is used:

${controller.item.dueDate | dateFormat}

Is there anything else I need to do?

jods4 commented

Hard to say without more context but something very wrong is going on because

  1. The module name was not preserved and changed to 207
  2. Exports where considered unused /* unused harmony export DateFormatValueConverter */

I suspect that you ES import this module somewhere else, which is why it ends up in the build.

I also suspect that PLATFORM.moduleName is not working properly for some reason that I can't guess.

Your correct. I had it imported as well, so I took that out. See the updated information above. It is giving me a different error message now.

jods4 commented

You should use absolute path moduleName('core/...').
Relative path is used in feature or plugin configuration function. That's how Aurelia works <_>

(Generally speaking you should use absolute paths everywhere inside your own application)

Yes, that worked.

My conversion from system.js to webpack on a fairly major project is now complete.

Thank you for your hard work and support.