I am trying to use babel standalone inside a react app to transpile Angular TypeScript. The transpiling does "work" however I get an error when I try to import a component and use it's selector inside the template of another component.
This is the error I get:
Uncaught Error: Template parse errors:
'search-bar' is not a known element:
1. If 'search-bar' is an Angular component, then verify that it is part of this module.
2. If 'search-bar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
SearchBar Component (user code):
// ng is on the window object
const { Component, NgModule, Output, EventEmitter } = ng.core;
const { CommonModule } = ng.common;
@Component({
selector: 'search-bar',
template: `<div>Search Bar</div>`,
})
@NgModule({
declarations: [SearchBar],
exports: [SearchBar]
})
class SearchBar {}
export default SearchBar;
App Component (user code):
const { Component, NgModule, VERSION } = ng.core;
const { CommonModule } = ng.common;
// Note: The online editor does not need a path to the component :)
import SearchBar from 'SearchBar.ts';
@NgModule({
imports: [
CommonModule,
SearchBar,
],
declarations: [AppComponent, SearchBar],
})
@Component({
selector: 'my-app',
template: `<search-bar></search-bar>`
})
export default class AppComponent {
}
Please note, I am creating an online code editor so yes I need to use babel standalone. Here is my babel config for typescript:
(from my react app)
const TS_OPTIONS = {
presets: [
['typescript', { allExtensions: true }],
['es2017', { 'modules': false }],
],
plugins: [
["proposal-decorators", { "legacy": true }],
["proposal-class-properties", { "loose" : true }],
'transform-modules-commonjs',
],
};
version of Babel:
https://unpkg.com/@babel/standalone@7.12.9/babel.min.js
My transpile function (simplified, also from my react app):
export default function transpile(myCode) {
const { code } = Babel.transform(myCode, TS_OPTIONS);
return myCode;
}
What am I missing?