aurelia / webpack-plugin

A plugin for webpack that enables bundling Aurelia applications.
MIT License
90 stars 36 forks source link

aurelia-templating-resources loaded before PAL is initialized #103

Closed Mordred closed 7 years ago

Mordred commented 7 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: When you import aurelia-templating-resources during configure, PAL.moduleName will load all resources before aurelia-pal-browser is initialized. Then when you try to use

<div show.bind="true">Yes!</div>

error is thrown:

Error: Error invoking Show. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?

image

Expected/desired behavior:

I have created minimal steps to reproduce this bug on aurelia-skeleton-navigation: https://github.com/Mordred/skeleton-navigation/commit/9d9b991f7bed8a90404c5e06974ef2cf1d0eba85

jods4 commented 7 years ago

I'm closing this as a duplicate of aurelia/pal-browser#17, please make yourself heard over there and follow that thread for feedback.

From that thread, it's clear that loading some Aurelia modules before the PAL is initialized breaks the DI, specifically leads to inability to inject DOM.Element and friends.

It's not directly related to Webpack. I'm pretty sure the trigger in your repro is the addition in main.js of

import { BindingSignaler } from 'aurelia-templating-resources';

This loads Aurelia libs before the PAL is actually initialized (said initialization is performed by aurelia-bootstrapper).

I would say it's unfortunate that importing without actually using anything triggers this bug and that's probably what we should fix. But that's the current situation.

BTW: since you don't seem to use BindingSignaler, removing that line should work around the problem.

Mordred commented 7 years ago

That was only minimal code, so that you can reproduce it

My real code is more complicated ... I'm importing aurelia-i18n, which is importing aurelia-templating-resources.

And I think this is related to how webpack-plugin imports globalResources.

I'm rewriting jspm to webpack and this wasn't issue on the jspm. On jspm they were loaded when needed, but on webpack, they are bundled and loaded directly.

jods4 commented 7 years ago

The plugin doesn't "load" globalResources.

As I said the trigger in your repro is the import. It will load aurelia-framework and friends and as described in the PAL issue, it was identified that loading framework libraries before the PAL is initialized leads to this bug.

Webpack might make this issue more visible because all imports are satisfied synchronously, which might change the timing. That said, the original issue was posted by a JSPM user.

jods4 commented 7 years ago

I'm going to ask for the skeleton to be changed. If you set your entry to aurelia-bootstrapper and remove it from main everything should be alright. Look here for examples: https://github.com/jods4/aurelia-webpack-build

Bootstrapping from the main file directly is bad because of this very issue.

Mordred commented 7 years ago

Thanks man,

it's working now.

One note: I had to change aureliaApp to reference my app/main because I'm using different file than default.