1

使用 ngc 编译我的 Angular 2 应用程序后,我遇到了 Rollup 错误。有没有其他人克服了这个问题?

Error: '$$observable' is not exported by  node_modules/rxjs/symbol/observable.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module

这是我的 package.json:

"dependencies": { "@angular/common": "~2.4.0", "@angular/compiler": "~2.4.0", "@angular/compiler-cli": "~2.4.0", "@angular/core": "~2.4.0", "@angular/forms": "~2.4.0", "@angular/http": "~2.4.0", "@angular/platform-browser": "~2.4.0", "@angular/platform-browser-dynamic": "~2.4.0", "@angular/platform-server": "~2.4.0", "@angular/router": "~3.4.1", "angular-in-memory-web-api": "~0.1.16", "core-js": "^2.4.1", "reflect-metadata": "~0.1.8", "rxjs": "~5.2.0", "systemjs": "0.19.41", "zone.js": "^0.7.2", "express": "^4.14.0", "http": "0.0.0", "https": "^1.0.0" }, "devDependencies": { "@types/core-js": "^0.9.35", "@types/jasmine": "^2.5.36", "@types/karma": "^0.13.33", "@types/node": "^6.0.45", "autoprefixer": "^6.5.1", "babel-cli": "^6.14.0", "babel-preset-es2015": "^6.14.0", "canonical-path": "0.0.2", "chalk": "^1.1.3", "chokidar": "^1.6.0", "clim": "^1.1.1", "codelyzer": "1.0.0-beta.3", "concurrently": "^3.0.0", "core-js": "^2.4.1", "cssnano": "^3.8.0", "google-closure-compiler": "^20160911.0.0", "google-closure-compiler-js": "^20160916.0.0", "htmlprocessor": "^0.2.4", "http-server": "^0.9.0", "jasmine-core": "^2.3.4", "jasmine-spec-reporter": "^2.4.0", "karma": "1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "^1.0.0", "karma-htmlfile-reporter": "^0.3.4", "karma-jasmine": "^1.0.2", "karma-jasmine-html-reporter": "^0.2.2", "karma-mocha-reporter": "^2.0.3", "karma-phantomjs-launcher": "^1.0.0", "karma-remap-istanbul": "0.2.1", "karma-verbose-reporter": "0.0.3", "live-server": "^1.1.0", "livereload": "^0.6.0", "node-sass": "^3.10.1", "nodemon": "^1.10.2", "npm-run-all": "^3.0.0", "onchange": "^3.0.2", "phantomjs-prebuilt": "^2.1.13", "postcss": "^5.2.5", "postcss-cli": "^2.6.0", "protractor": "^4.0.10", "remap-istanbul": "^0.7.0", "replace-in-file": "^2.0.1", "rimraf": "^2.5.1", "rollup": "^0.41.4", "rollup-plugin-alias": "^1.2.0", "rollup-plugin-angular": "=0.4.2", "rollup-plugin-cleanup": "^1.0.0", "rollup-plugin-commonjs": "^7.0.0", "rollup-plugin-includepaths": "^0.2.1", "rollup-plugin-node-resolve": "^2.0.0", "rollup-plugin-replace": "^1.1.1", "rollup-plugin-typescript": "^0.8.1", "rollup-plugin-uglify": "^1.0.1", "shelljs": "^0.7.5", "traceur": "0.0.111", "ts-helpers": "^1.1.2", "tslint": "^3.15.1", "typescript": "^2.0.3", "watchify": "^3.7.0" }

4

1 回答 1

1

好的,它适用于这些依赖项:

"dependencies": { "@angular/common": "2.4.7", "@angular/compiler": "2.4.7", "@angular/compiler-cli": "2.4.7", "@angular/core": "2.4.7", "@angular/forms": "2.4.7", "@angular/http": "2.4.7", "@angular/platform-browser": "2.4.7", "@angular/platform-browser-dynamic": "2.4.7", "@angular/platform-server": "2.4.7", "@angular/router": "3.4.7", "angular-in-memory-web-api": "~0.2.4", "core-js": "^2.4.1", "reflect-metadata": "~0.1.8", "rxjs": "5.1.0", "systemjs": "0.20.7", "zone.js": "^0.7.6", "express": "^4.14.0", "http": "0.0.0", "https": "^1.0.0" }, "devDependencies": { "@types/core-js": "^0.9.35", "@types/jasmine": "^2.5.36", "@types/karma": "^0.13.33", "@types/node": "^6.0.45", "autoprefixer": "^6.5.1", "babel-cli": "^6.14.0", "babel-preset-es2015": "^6.14.0", "canonical-path": "0.0.2", "chalk": "^1.1.3", "chokidar": "^1.6.0", "clim": "^1.1.1", "codelyzer": "^2.0.1", "concurrently": "^3.0.0", "core-js": "^2.4.1", "cssnano": "^3.8.0", "google-closure-compiler": "^20160911.0.0", "google-closure-compiler-js": "^20160916.0.0", "htmlprocessor": "^0.2.4", "http-server": "^0.9.0", "jasmine-core": "^2.3.4", "jasmine-spec-reporter": "^2.4.0", "karma": "1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "^1.0.0", "karma-htmlfile-reporter": "^0.3.4", "karma-jasmine": "^1.0.2", "karma-jasmine-html-reporter": "^0.2.2", "karma-mocha-reporter": "^2.0.3", "karma-phantomjs-launcher": "^1.0.0", "karma-remap-istanbul": "0.2.1", "karma-verbose-reporter": "0.0.3", "live-server": "^1.1.0", "livereload": "^0.6.0", "node-sass": "^3.10.1", "nodemon": "^1.10.2", "npm-run-all": "^3.0.0", "onchange": "^3.0.2", "phantomjs-prebuilt": "^2.1.13", "postcss": "^5.2.5", "postcss-cli": "^2.6.0", "protractor": "^4.0.10", "remap-istanbul": "^0.7.0", "replace-in-file": "^2.0.1", "rimraf": "^2.5.1", "rollup": "^0.41.4", "rollup-plugin-alias": "^1.2.0", "rollup-plugin-angular": "=0.4.2", "rollup-plugin-cleanup": "^1.0.0", "rollup-plugin-commonjs": "^7.0.0", "rollup-plugin-includepaths": "^0.2.1", "rollup-plugin-node-resolve": "^2.0.0", "rollup-plugin-replace": "^1.1.1", "rollup-plugin-typescript": "^0.8.1", "rollup-plugin-uglify": "^1.0.1", "shelljs": "^0.7.5", "traceur": "0.0.111", "ts-helpers": "^1.1.2", "tslint": "^4.3.0", "typescript": "~2.1.6", "watchify": "^3.7.0" }

而这个 rollup.config.js

import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import commonjs from 'rollup-plugin-commonjs';

export default {
  entry: 'main.prod.js',
  format: 'iife',
  dest: 'dist/bundle.es2015.js',
  sourceMap: false,
  treeshake: true,
  plugins: [
    replace({ 'ENVIRONMENT': JSON.stringify( 'production' ) }),
    commonjs({
     include: 'node_modules/rxjs/**'
    }),
    resolve({ jsnext: true, module: true }),
    cleanup()
  ],
  onwarn: function ( message ) {
    if ( /at the top level of an ES module, and has been rewritten/.test( message ) ) {
      return;
    }
    console.error( message );
  }
}

于 2017-02-27T03:13:24.350 回答