Angular 7 - 收到错误消息“模块解析失败:意外字符‘@’”如何解决?

Angular 7 - getting error as `Module parse failed: Unexpected character '@'` how to fix this?

在我的 Interceptor 文件中,我得到一个错误:

ERROR in ./src/app/auth/auth.interceptor.js 8:0
Module parse failed: Unexpected character '@' (8:0)
You may need an appropriate loader to handle this file type.
| import { UserService } from "./../shared/user.service";
|
> @Injectable()
| export class AuthInterceptor implements HttpInterceptor {
|

如何解决这个问题?这是我的 ts 文件:

import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { tap } from "rxjs/operatos";
import { Router } from "@angular/router";

import { UserService } from "./../shared/user.service";

@Injectable()
export class AuthInterceptor implements HttpInterceptor {

    constructor(private userService:UserService, private router:Router){}

    intercept(req:HttpRequest<any>, next:HttpHandler){
        if(req.headers.get('noauth')){
            return next.handle(req.clone());
        }
        else{
            const clonedreq = req.clone({
                headers:req.headers.set('Authorization', 'Bearer ' + this.userService.getToken())
            })
            return next.handle(clonedreq).pipe(tap(event => {}, err => {
                if(err.error.auth === false ){
                    this.router.navigateByUrl('/login');
                }
            } ))
        }
    }
}

我没有发现任何错误,此语法在 Typescript 中对我来说似乎有效。但您似乎将其用作 javascript:将您的文件扩展名从 js 更改为 ts,消息应该会消失。