For some context, I’m transferring a project from the requirejs bundler to webpack.
The Problem: Each required template is throwing errors in console:
Error: Unable to find module with ID: elements/hud/hud.html
When I change the require path from elements/hud/hud
to resources/elements/hud/hud
it moves onto errors for the next required template and so on.
au build doesn’t throw errors or warnings. webpack.config.js has the “alias” set up for the resources sub-directories (otherwise it would error on the build):
I don’t think it matters, but the aurelia.json also has the “path” set:
"elements": "resources/elements"
Hoping I’m just missing something obvious for getting the templates working because this is a legacy app with hundreds of templates and I don’t want to update every single path in a
In troubleshooting, I found that each custom element is being bundled without “resources” in the module id and then it’s subcomponent files (.js, .less, .html, etc) are being bundled with module ids that start with “resources”. Not sure what that would happen, but perhaps it’s a hint to someone with more framework knowledge than me.
The Basic Example is not helpful in this circumstance. I’ve already updated the main.js and routes in app.js to use PLATFORM.moduleName(…).
The issue is that the <require from=“…”> elements in my templates are no longer working. Templating: HTML Behaviors Introduction | Aurelia doesn’t say my from attribute should be formatted differently for webpack.
Here are the files I can share. Let me know if I missed something…
Correct, that doesn’t work. Webpack can’t resolve the modules if I do that.
I think the root issue might be in the Aurelia Webpack Plugin and how it handles non js files. It should take aliases (aka paths) into account so ‘resources’ is dropped from the module name, but for some reason it is only doing that for js files. I tried some tricks with @useView and @inlineView but it still makes the moduleId with resource at the start of the path.
Later today I’ll spin up a fresh, minimal project with the same folder structure to see if that fails as well
Oh interesting, so each individual custom element is listed relative to resources/index. Hmm that won’t be fun haha. We have a couple hundred. I’ll give that a test though later today
I’ve started from a fresh project and am seeing the same errors. I start by creating a new element with the CLI which creates 2 files in resource directory. Then I require that file in the app.html. Webpack complains that it cannot resolve the required file, so I add an alias for the elements directory. Everything bundles and I get the same errors as before. Think I’m ready to submit this as a bug?