aurelia / loader-webpack

An implementation of Aurelia's loader interface to enable webpack.
MIT License
26 stars 10 forks source link

We have to delete cache of wepback when __webpack_require__ fail. #18

Closed alu closed 7 years ago

alu commented 7 years ago

This loader does try load any modules by webpack_require. The code is here.

Webpack always caches to information of module. Please look following sample (generated by webpack).

/******/    // The require function
/******/    function __webpack_require__(moduleId) {
                                ////// 2. so we can't get module exports
/******/                if (installedModules[moduleId]) return installedModules[moduleId].exports;

                                ////// 1. always cache!!
/******/                var module = installedModules[moduleId] = {
/******/                  i: moduleId,
/******/                  l: false,
/******/                  exports: {}
/******/                };

/******/                if (!modules[moduleId] && typeof moduleId === 'string') {
/******/                  var newModuleId;
/******/                  if (modules[newModuleId = moduleId + '.js'] || modules[newModuleId = moduleId + '.ts']) {
/******/                    moduleId = newModuleId;

/******/                    installedModules[moduleId] = module;
/******/                  }
/******/                }

/******/                modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/                module.l = true;

/******/                return module.exports;
/******/    }

So, if you try require.ensure after __webpack_require__, we can't get module exports.

We have to delete the cache.

try {
  // first try native webpack method //
  const result = __webpack_require__(path);
  return this._getActualResult(result, resolve, reject);
} catch (_) {
  // delete the cache
  delete __webpack_require__.c[path];
}

or check the module exists before __webpack_require__.

if (__webpack_require__.m[path] !== undefined) {
  const result = __webpack_require__(path);
  ...
} {
  require.ensure([], require => {
  ...
}

Thank you.

niieani commented 7 years ago

Good catch, thanks. I've made the correction.

alu commented 7 years ago

Thanks for fix!

I waiting for next version that are includes this fix :)

alu commented 7 years ago

@niieani Do you have plan that release new version?

niieani commented 7 years ago

I'm working on some more fixes and thought I'd make them all before new releases, but I guess we could make a bugfix release with just this one change, since I don't know when I'll be ready with other fixes. @EisenbergEffect loader-webpack should be okay to release with this fix.

alu commented 7 years ago

@niieani OK, Thank you for response!

alu commented 7 years ago

@EisenbergEffect Please check this, because i can't upgrade to aurelia 1.x, depend on this issue.

EisenbergEffect commented 7 years ago

@niieani I must have missed this somehow. Are you still good for a release?

niieani commented 7 years ago

@EisenbergEffect yes, let's do it! :) I was wondering why it didn't get released along with the recent updates.

niieani commented 7 years ago

Released!

alu commented 7 years ago

Thanks!