# Aurelia webpack: compose gives module not found

**URL:** https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308
**Category:** Uncategorized
**Created:** [February 22, 2019, 1:58pm UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308 "2019-02-22T13:58:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![WalterEbbers](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/walterebbers/32/1576_2.png) [@WalterEbbers](https://discourse.aurelia.io/u/WalterEbbers)
#### Post date: [February 22, 2019, 1:58pm UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308/1 "2019-02-22T13:58:45Z")

</div>

Hi!  
Is there someone who could help me with the following?  
i have a compose in my view that binds to a view i said in my model.  
The view is build as follow:

```
private baseWizardSummariesPath: string = 'components/clients/wizard/summaries/';
private baseTargetPath: string = 'components/clients/wizard/dialogs/';
private baseIconPath: string = 'shared/resources/elements/svg/';
private stepSummaryTemplatePath: string = "scope-summary/scope-summary.html";

//components/clients/wizard/summaries/scope-summary/scope-summary.html
let summaryTemplatePath: string = PLATFORM.moduleName(this.baseWizardSummariesPath + stepSummaryTemplatePath);

```

view with compose: shared/components/wizard/sub-wizard-step-component.html  
Compose:  
`<compose view.bind="subWizardStep.stepSummaryTemplatePath"></compose>`

the error i’m getting:

`Unhandled rejection Error: Unable to find module with ID: components/clients/wizard/summaries/scope-summary/scope-summary.html`

am i missing something.?

---

<div class="post-metadata">

### Author: ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)
#### Post date: [February 22, 2019, 2:15pm UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308/2 "2019-02-22T14:15:10Z")

</div>

It’s not possible for webpack to know what module to add to the bundle with this:

```auto
//components/clients/wizard/summaries/scope-summary/scope-summary.html
let summaryTemplatePath: string = PLATFORM.moduleName(this.baseWizardSummariesPath + stepSummaryTemplatePath);

```

What you want to do is to have string literal like following:

```auto
PLATFORM.moduleName('components/clients/wizard/summaries/scope-summary/scope-summary.html')
// ....
// then you can do

private baseWizardSummariesPath: string = 'components/clients/wizard/summaries/';
private baseTargetPath: string = 'components/clients/wizard/dialogs/';
private baseIconPath: string = 'shared/resources/elements/svg/';
private stepSummaryTemplatePath: string = "scope-summary/scope-summary.html";

//components/clients/wizard/summaries/scope-summary/scope-summary.html
let summaryTemplatePath: string = PLATFORM.moduleName(this.baseWizardSummariesPath + stepSummaryTemplatePath);

```

---

<div class="post-metadata">

### Author: ![WalterEbbers](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/walterebbers/32/1576_2.png) [@WalterEbbers](https://discourse.aurelia.io/u/WalterEbbers)
#### Post date: [February 22, 2019, 2:20pm UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308/3 "2019-02-22T14:20:41Z")

</div>

> [@bigopon](#):
>
> PLATFORM.moduleName(‘components/clients/wizard/summaries/scope-summary/scope-summary.html’)

Thnx!  
although after changing this i’m running against the following:  
`No view model found in module "components/clients/wizard/dialogs/scope-dialog/scope-dialog.html".`

not sure why since the scope-dialog folder contains a scope-dialog.ts

---

<div class="post-metadata">

### Author: ![timfish](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/timfish/32/1566_2.png) [@timfish](https://discourse.aurelia.io/u/timfish)
#### Post date: [February 22, 2019, 4:37pm UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308/4 "2019-02-22T16:37:18Z")

</div>

We have perhaps 100 view models that are looked up dynamically and we didn’t want to list them all in a single place that would get forgotten when adding new ones.

[`require.context(path, deep, regex)`](https://webpack.js.org/guides/dependency-management/#requirecontext) to the rescue!

Our components are all organised into directories which are located using the following compose paths in `./devices/list.html`:

```auto
view-model="./${device.type}/components/list-item"
view-model="./${device.type}/components/${channel.type}-edit"

```

All the view models could be found using a glob like:

```auto
./devices/**/components/*.ts

```

At the top of `./devices/list.ts` I added the following:

```auto
require.context('./', true, /\/components\/.*.ts$/)

```

If you’re using TypeScript, you can add `@types/webpack-env` to your `devDependencies` for `require.context` typings.

Now Webpack picks up all our viewModels (and corresponding views) without having to reference each one manually.

---

<div class="post-metadata">

### Author: ![WalterEbbers](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/walterebbers/32/1576_2.png) [@WalterEbbers](https://discourse.aurelia.io/u/WalterEbbers)
#### Post date: [February 25, 2019, 7:24am UTC](https://discourse.aurelia.io/t/aurelia-webpack-compose-gives-module-not-found/2308/5 "2019-02-25T07:24:33Z")

</div>

Thnx! @timfish  
i’ll try and see if this is workable in the project i’m working on.

Quick question about the device/list part. Is this just a component in your aurelia/ webpack project?  
And how does this work in the following situation?

`components/clients/wizard/wizard.html`  
`components/clients/wizard/dialogs/scope-dialog/scope-dialog.html`

Where scope-dialog is part of the wizard.

We always keep parts that belong together within the same base dir like my example above.

Edit:  
I currently fixed my problem in a other way by setting the viewmodel within the dialogservice with PLATFORM.moduleName() instead of what i first had(setting a string with moduleName and passing it to a method that calls dialogService).
