Looking for a solution:
https://github.com/napolev/stencil-cannot-find-name
In this project, there are two main files to consider:
custom-container.tsx
import { Component, Element, State } from '@stencil/core';
@Component({
tag: 'custom-container',
styleUrl: 'custom-container.scss',
})
export class WebComponent {
@Element() el!: HTMLStencilElement;
@State() label: String = '<empty>';
componentDidLoad() {
document.querySelector('.button_get_anchor').addEventListener('click', () => {
let position = '<unset>';
position = this.el.querySelector('custom-details').getDefaultKnobEPosition();
this.label = position;
});
}
render() {
return [
<div class="label">{this.label}</div>,
<custom-details></custom-details>,
<div>
<button class="button_get_anchor">Get Anchor</button>
</div>
];
}
}
custom-details.tsx
import { Component, Method } from '@stencil/core';
@Component({
tag: 'custom-details',
styleUrl: 'custom-details.scss',
})
export class WebComponent {
render() {
return [
<div class="details">This is the "custom-details"</div>
];
}
@Method()
sayHelloWorldOnConsole() {
console.log('Hello World!');
}
@Method()
getDefaultKnobEPosition(): Anchor {
return Anchor.Left;
}
}
export enum Anchor {
Left = 'left',
Center = 'center',
Right = 'right',
}
The Issue: After running $ npm start --es5
, an error occurs regarding the 'Anchor' name not being found.
[ ERROR ] TypeScript: ./stencil-cannot-find-name/src/components.d.ts:66:39
Cannot find name 'Anchor'.
...
You can see the error in this image:
https://i.stack.imgur.com/2iWZN.png
Moreover, Visual Studio Code also highlights this issue as shown here:
https://i.stack.imgur.com/Wer7m.png
The problematic line can be viewed at:
https://github.com/napolev/stencil-cannot-find-name/blob/master/src/components.d.ts#L66
This file is auto-generated and cannot be modified directly. Any suggestions on resolving this?
Thanks!