aurelia / hot-module-reload

Core functionality for Aurelia's hot-module-reolad (HMR) capabilities, which is shared by all loaders and tools.
MIT License
25 stars 8 forks source link

Container.instance undefined #14

Closed ghost closed 6 years ago

ghost commented 7 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: We have a ASP.NET Core project serving an API with Aurelia as SPA (also served by ASP.NET Core and packed with Webpack, inspired by https://github.com/aspnet/JavaScriptServices/tree/dev/templates/AureliaSpa). When we run our minimal setup with only a main.js, app.js and frontpage.js with almost no content, we receive the following error:

Uncaught (in promise) TypeError: Cannot read property 'get' of undefined
    at new HmrContext (aurelia-hot-module-reload.js:38)
    at WebpackLoader.<anonymous> (aurelia-loader-webpack.js:67)
    at Generator.next (<anonymous>)
    at aurelia-loader-webpack.js:6
    at Promise (<anonymous>)
    at 58.__awaiter (aurelia-loader-webpack.js:2)
    at Object.fetch (aurelia-loader-webpack.js:58)
    at WebpackLoader.<anonymous> (aurelia-loader-webpack.js:105)
    at Generator.next (<anonymous>)
    at aurelia-loader-webpack.js:6

The line that fails is this one: this.viewEngine = Container.instance.get(ViewEngine); (https://github.com/aurelia/hot-module-reload/blob/master/src/aurelia-hot-module-reload.ts#L42)

Expected/desired behavior: Execution should not fail.

I'm not sure if this is a bug, or a misconfiguration. Sorry if this shouldn't have been posted here.

ghost commented 7 years ago

I managed to extract further details:

bluebird.js:1542 Unhandled rejection TypeError: Cannot read property 'get' of undefined
    at new HmrContext (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:5496:115)
    at WebpackLoader.<anonymous> (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51314:43)
    at Generator.next (<anonymous>)
    at http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51251:71
    at 272.__awaiter (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51247:12)
    at Object.fetch (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51305:34)
    at WebpackLoader.<anonymous> (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51352:37)
    at Generator.next (<anonymous>)
    at http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51251:71
From previous event:
    at 272.__awaiter (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51247:12)
    at WebpackLoader.loadModule (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51417:16)
    at WebpackLoader.loadTemplate (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51440:21)
    at ensureRegistryEntry (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:64340:17)
    at ViewEngine.loadViewFactory (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:64393:12)
    at ConventionalViewStrategy.loadViewFactory (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:61928:23)
    at HtmlBehaviorResource.load (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65125:27)
    at ensureViewModel.then.then (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65666:16)
From previous event:
    at CompositionEngine.createController (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65654:69)
    at CompositionEngine._createControllerAndSwap (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65637:17)
    at CompositionEngine.compose (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65711:19)
    at TemplatingEngine.compose (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:65955:36)
    at Aurelia.setRoot (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:120733:19)
    at http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:132362:24
From previous event:
    at Object.configure (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:132361:21)
    at aurelia.loader.loadModule.then.customConfig (http://localhost:5000/dist/app.bundle.js?v=IUhWTH7NiQklOTCxwmK1r_P_-7xHfTdHoSxlOQ8imHk:51200:27)
    at tryCatcher (http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:7495:23)
    at Promise._settlePromiseFromHandler (http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:5517:31)
    at Promise._settlePromise (http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:5574:18)
    at Promise._settlePromise0 (http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:5619:10)
    at Promise._settlePromises (http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:5698:18)
    at http://localhost:5000/dist/vendor.bundle.js?v=kUaq_PCpbOzaDZCDDloku6mnkugeNdYmom5hSEB9AiA:2417:25
    at <anonymous>

If I import aurelia-dependecy-injection and access Container.instance (by issuing a simple console.log) in the constructor or activate method in the root component (set by aurelia.setRoot) it is not undefined.

I'm not sure what kind of details you need, so please state so.

niieani commented 7 years ago

Can you provide a minimal repo which reproduces the issue?

ghost commented 7 years ago

I wish I could, but it's not possible to easily reproduce. The project we are working on has been using the Aurelia CLI until now, but we wish to migrate to Webpack because of performance reasons. What we currently have ended up doing, are creating a completely new project from scratch, and then transfer all logic slowly, and then hopefully we will experience the bug at some point, and be able to create a small repo reproducing this issue. If OK with you, I will return when we have more information.

niieani commented 7 years ago

Yes, that's fine. Just remember that HMR is experimental/unstable.

Alexander-Taran commented 6 years ago

@boysensci please share if you have been able to repro or found a solution

ghost commented 6 years ago

I haven't. What I ended up with (months ago), was to recreate a ASP.NET Core project, and then it worked. I don't think the problem was with Aurelia, but with Webpack.