During my Karma (Jasmine) test run, I was occasionally see this error:
Unable to find module with ID: plugin/index
Facts:
- I’m using Webpack 4.1.1 and TypeScript
- aurelia-bootstrapper 2.2.0
- aurelia-webpack-plugin 3.0.0
- aurelia-loader-webpack 2.2.1
- My project is an Aurelia plugin with a demo application included
- The src/plugin/index.ts file, as is our practice, includes a config.globalResources() call will all my elements referenced like: config.globalResources( [PLATFORM.moduleName(’./elements/something/index’), PLATFORM.moduleName(’./elements/something-else/index’) …
- My demo application’s main.ts references the plugin’s index using: .feature(PLATFORM.moduleName(‘plugin/index’))
- It’s the same error message each time, but occurred “randomly” without any pattern I can discern.
After some tinkering with aurelia-loader-webpack in which I added some console output to import() after the line:
moduleId = addressParts.splice(addressParts.length - 1, 1)[0];
… I discovered that when my error occurs, it is always after importing the same resource file (referenced in plugin/index’s global resources array). Inside that TypeScript file, I noticed that it was importing another file, which happened to be named “index.ts” and in the same path, using this syntax:
import { SomeOtherThing } from '.';
For the fun of it, I changed it to:
import { SomeOtherThing } from './index';
To my surprise, my error no longer reared it’s ugly head. So my question is this: Why would the “.” vs “./index” have an impact, and why do things go awry randomly?
Any ideas?