升级Angular项目至最新版本后,RxJS Subscription导出成员缺失问题求助
Hey there, I’ve run into this exact snag when upgrading to Angular 6, so let’s walk through how to fix it step by step.
Why This Happens
Angular 6 ships with RxJS 6.x, which introduced breaking changes to import paths. The old way of importing core RxJS types like Subscription was completely deprecated and removed in this version—so your code is looking for a file structure that no longer exists.
Step 1: Make Sure You’re on the Right RxJS Version
First, check your package.json to confirm you have the correct RxJS version paired with Angular 6. You need RxJS 6.0.0 or higher. If it’s missing or outdated, install it via npm:
npm install rxjs@6.3.3 --save
(6.3.3 is the stable, recommended version for Angular 6, but any 6.x release will work)
Step 2: Update Your Import Statements
The core fix is adjusting how you import Subscription. Replace every instance of this old import:
import { Subscription } from 'rxjs/Subscription';
With this new syntax:
import { Subscription } from 'rxjs';
This same rule applies to other core RxJS types like Observable, Subject, or BehaviorSubject—all now import directly from the root rxjs package.
Optional: Temporary Compatibility with rxjs-compat
If you have a massive codebase and can’t update all imports at once, you can install the rxjs-compat package to bridge the gap between RxJS 5 and 6 syntax:
npm install rxjs-compat@6.3.3 --save
Just note this is a short-term workaround—rxjs-compat isn’t meant for long-term use, so plan to migrate to the new import syntax as soon as you can.
Final Check
After making these changes, run your build again to verify:
ng build
That Subscription error should be gone for good!
内容的提问来源于stack exchange,提问作者Øystein Seel

