Another RXJS "ERROR TypeError: Object(...) is not a function" problem

Another RXJS "ERROR TypeError: Object(...) is not a function" problem

我在 Whosebug 和其他网站上查看过,但我看到或尝试过的任何东西似乎都没有帮助,所以我把它扔在这里。

当我进行简单构建时 ng b 一切 运行 都很好。当我使用 ng b --prod --aot=true 然后 运行 构建我们的应用程序时,我得到以下异常:

ERROR TypeError: Object(...) is not a function
    at CG.getAPIURLs (main.f5019b5d20f499feb949.js:1)
    at new Ou (main.f5019b5d20f499feb949.js:1)
    at Sn (main.f5019b5d20f499feb949.js:1)
    at xn (main.f5019b5d20f499feb949.js:1)
    at Cr (main.f5019b5d20f499feb949.js:1)
    at br (main.f5019b5d20f499feb949.js:1)
    at Object.Rr [as createRootView] (main.f5019b5d20f499feb949.js:1)
    at Kl.create (main.f5019b5d20f499feb949.js:1)
    at gt.create (main.f5019b5d20f499feb949.js:1)
    at Di.bootstrap (main.f5019b5d20f499feb949.js:1)
ee @ main.f5019b5d20f499feb949.js:1

我运行宁Angular版本9如下:

Angular CLI: 9.1.7
Node: 16.10.0
OS: win32 x64

Angular: 9.1.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: No

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.7
@angular-devkit/build-angular     0.901.7
@angular-devkit/build-optimizer   0.901.7
@angular-devkit/build-webpack     0.901.7
@angular-devkit/core              9.1.7
@angular-devkit/schematics        9.1.7
@angular/cli                      9.1.7
@angular/http                     7.2.16
@ngtools/webpack                  9.1.7
@schematics/angular               9.1.7
@schematics/update                0.901.7
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.42.0

代码如下:

import { APIURLType } from './types/apiurl.type';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable  } from '../../../node_modules/rxjs/Observable';
import { of } from '../../../node_modules/rxjs/Observable/of';
import { environment } from './../../environments/environment';

@Injectable()
export class APIPathService {

    public aPIPathURLs: APIURLType;
    public kind = 'nothing';
    public environmentAPI: APIURLType = environment;

    constructor(public httpClient: HttpClient) {
        console.log('APIPathURL.service.ts');
    } // ends constructor

    getAPIURLs(): Observable<APIURLType> {
        console.log('Environment API: ' + this.environmentAPI.rootPath);
        return of(this.environmentAPI);

    } // ends getAPIURLs
} // ends class APIPathService

我想知道是否应该升级所有内容,因为我没有想法。任何线索将不胜感激。

TTFN

蒂姆

您的 rxjs 导入看起来不正确尝试:

import { Observable, of } from 'rxjs';

npm 模块的导入永远不会以相对路径开头,例如./../../..。您的 IDE 应该会自动生成这些导入语句(我使用 VSCode)