I have a js file as shown below UserService.js and source.js which is created using transformer typescript my goal is to use this transformed js file in angular.
UserService.js
import { Source } from "./source";
export class UserService {
source = new Source();
demo() {
this.source.fun();
}
}
Sourcr.js
export class Source {
fun() {
console.log('hello world');
}
}
When I try to use the file in app.component.ts as shown below
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
userService=new UserService();
constructor() { }
ngOnInit(): void {
this.userService.demo();
}
}
Below is tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
}
I get the following error while doing ng serve
ERROR in ./dist/out-tsc/UserService.js 4:11
Module parse failed: Unexpected token (4:11)
You may need an appropriate loader to handle this file type.
| export class UserService {
|
> source = new Source();
|
| demo() {