Skip to content

Instantly share code, notes, and snippets.

@michaelnero
Last active September 9, 2022 11:33
Show Gist options
  • Save michaelnero/ffa1104721943effa44dc1802caa7427 to your computer and use it in GitHub Desktop.
Save michaelnero/ffa1104721943effa44dc1802caa7427 to your computer and use it in GitHub Desktop.
Aurelia node resolve error
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.ts.
-->
<body>
<my-app></my-app>
<script src="/dist/entry-bundle.js" data-main="main"></script>
</body>
</html>
{
"dependencies": {
"aurelia": "latest"
}
}
import Aurelia, { RouterConfiguration} from 'aurelia';
import { MyApp } from './my-app';
Aurelia.register(RouterConfiguration).app(MyApp).start();
<import from="./my-component"></import>
<div class="message">${message}</div>
<au-viewport default="my-component"></au-viewport>
export class MyApp {
public message: string = 'Hello Aurelia 2!';
}
<import from="./sub-component"></import>
<div>This is my component</div>
<sub-component></sub-component>
import { inject } from "aurelia";
import { INode } from "@aurelia/runtime-html";
import { IMyService } from "./my-service";
export class MyComponent {
constructor(
@INode private readonly node: INode<Element>, // Remove this, and you won't get an error
@IMyService private readonly service: IMyService) { // This always works
this.node.id = "some-id";
}
}
<!-- Note that this method also fails
@inject(Element)
export class MyComponent {
constructor(private readonly node: Element) {
this.node.id = "some-id";
}
}
-->
import { DI } from "aurelia";
export const IMyService = DI.createInterface<IMyService>(x => x.singleton(MyService));
export interface IMyService extends MyService { }
export class MyService {
}
<div>Sub component</div>
import { INode } from "aurelia";
export class SubComponent {
// The following works correctly
constructor(@INode private readonly node: INode<Element>) {
this.node.id = "sub-id";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment