Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

'default' is not exported by 'node_modules\rxjs\add\operator\toPromise.js' #255

Closed
kuangqifu opened this issue Nov 9, 2017 · 8 comments
Closed

Comments

@kuangqifu
Copy link

kuangqifu commented Nov 9, 2017

I am flowing the guide of "Ahead-of-Time Compilation",doing flowing in my project.

  1. install npm some dependence, execute: "npm install @angular/compiler-cli @angular/platform-server --save"
  2. create tsconfig-aot.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "typeRoots": [
      "./node_modules/@types/"
    ]
  },
  "files": [
    "app/app.module.ts",
    "app/main.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "aot",
    "skipMetadataEmit": true
  }
}
  1. execute: "node_modules/.bin/ngc" -p tsconfig-aot.json
  2. change main.ts content
import { platformBrowser }    from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory';

console.log('Running AOT compiled');
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
  1. execute: "node_modules/.bin/ngc" -p tsconfig-aot.json
    (it worked,created aot directory and files)
  2. install rollup same dependance. npm install rollup rollup-plugin-node-resolve rollup-plugin-commonjs rollup-plugin-uglify --save-dev
  3. add rollup-config.js file
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';

export default {
    entry: 'app/main.js',
    dest: 'app/build.js', // output a single application bundle
    sourceMap: false,
    format: 'iife',
    onwarn: function (warning) {
        // Skip certain warnings

        // should intercept ... but doesn't in some rollup versions
        if (warning.code === 'THIS_IS_UNDEFINED') { return; }

        // console.warn everything else
        console.warn(warning.message);
    },
    plugins: [
        nodeResolve({ jsnext: true, module: true }),
        commonjs({
            include: 'node_modules/rxjs/**',
        }),
        uglify()
    ]
};
  1. execute: "node_modules/.bin/rollup" -c rollup-config.js
    it create build.js file that is 558kb. but there are same infos:
    The following options have been renamed — please update your config: options.entry -> options.input, options.dest -> options.output.file, options.format -> options.output.format

app/main.js → app/build.js...
'default' is not exported by 'node_modules\rxjs\add\operator\toPromise.js'
created app/build.js in 15.3s
9. run my project in crome,error!
image

more infos:
my package.json

{
  "name": "ykframework",
  "version": "1.0.0",
  "description": "adminframework",
  "scripts": {
    "build": "tsc -p src/",
    "build:watch": "tsc -p src/ -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "keywords": [
    "admin",
    "framework"
  ],
  "author": "yunkai",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "^4.4.6",
    "@angular/common": "^4.4.4",
    "@angular/compiler": "~4.4.4",
    "@angular/core": "^4.4.4",
    "@angular/forms": "^4.4.4",
    "@angular/http": "^4.4.4",
    "@angular/platform-browser": "^4.4.4",
    "@angular/platform-browser-dynamic": "^4.4.4",
    "@angular/platform-server": "^5.0.1",
    "@angular/router": "^4.4.4",
    "@ngx-translate/core": "^8.0.0",
    "@ngx-translate/http-loader": "^2.0.0",
    "admin-lte": "^2.4.2",
    "angular-in-memory-web-api": "~0.3.0",
    "angular2-toaster": "^4.0.1",
    "bootstrap": "^3.3.7",
    "core-js": "2.4.1",
    "font-awesome": "^4.7.0",
    "ionicons": "^3.0.0",
    "jquery": "^3.2.1",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "0.7.4"
  },
  "devDependencies": {
    "@angular/cli": "1.0.3",
    "@angular/compiler": "^4.4.4",
    "@angular/compiler-cli": "^4.4.6",
    "@compodoc/compodoc": "^1.0.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "canonical-path": "0.0.2",
    "codelyzer": "~2.0.0",
    "concurrently": "^3.2.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.4",
    "protractor": "~5.1.0",
    "rimraf": "^2.5.4",
    "rollup": "^0.51.1",
    "rollup-plugin-commonjs": "^8.2.6",
    "rollup-plugin-node-globals": "^1.1.0",
    "rollup-plugin-node-resolve": "^3.0.0",
    "rollup-plugin-uglify": "^2.0.1",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  },
  "repository": {}
}

anyone help me.please!

@dhakehurst
Copy link

I managed to fix this with an npm upgrade,
angular 5.1.0
rxjs 5.5.5
typscript 2.6.2

etc

@milenaarmada
Copy link

I managed to fix this with rollup downgrade,

rollup@0.50.0
rollup-plugin-commonjs@8.2.4

@adrianheine
Copy link
Contributor

Can anybody reproduce this issue with current rollup and rollup-plugin-commonjs? If so, please provide a small, if not minimal case in a repository.

@fskreuz
Copy link

fskreuz commented Jan 27, 2018

Luckily, I stumbled across this one today. Minimal repo here https://github.com/fskreuz/rollup-rxjs-topromise-bug .

// src/index.js
import Rx from '@reactivex/rxjs'

export const foo = Rx.Observable.of('foo')
// src/rollup.config.js
import commonjs from 'rollup-plugin-commonjs'
import nodeResolve from 'rollup-plugin-node-resolve'

export default {
  plugins: [
    nodeResolve(),
    commonjs()
  ],
  input: 'src/index.js',
  output: { file: 'tmp/index.js', format: 'iife', name: 'foo' }
}
rollup -c src/rollup.config.js

Additional info: I came across this bug using Rollup 0.50 + commonjs 8.2.6. that repro uses Rollup 0.55 + commonjs 8.3.0.

@adrianheine
Copy link
Contributor

Since @reactivex/rxjs/dist/package/add/operator/toPromise.js is empty it's somewhat reasonable to get 'default' is not exported. It shouldn't cause any problems, though.

@fskreuz
Copy link

fskreuz commented Jan 28, 2018

Yup, the warning happens but the bundle is still created like normal. It's just that the warning doesn't look like a warning. Couple that with app errors that are probably unrelated, but happened at the same time...

image

😄

@crobinson42
Copy link

Why was this closed? I'm experiencing a similar issue with moment.js repo and searching for some information on how to resolve and landed here.

Using a straight forward config with rollup-plugin-node-resolve & rollup-plugin-commonjs then get this error when a React component imports the react-dates library (by airbnb) which relies on moment.js:

src/index.js → lib/bundle.es.js, lib/bundle.cjs.js...
[!] Error: 'default' is not exported by node_modules/moment/moment.js

Here's my config: https://gist.github.com/crobinson42/3266ea3a419a8c861094520114e925a7

You can run that with a simple create react app project and first get the error regarding Error: 'createPortal' is not exported by node_modules/react-dom/index.js which you can fix in namedExports but then installing react-dates react component lib and exporting that as a component will give the first error above ^.

Any thoughts on this? Should I do some more investigation to be useful? Thanks!

@wwwebman
Copy link

wwwebman commented Sep 26, 2018

Hi! What the status of this bug? It's still occur for me:

{
 "rollup": "^0.66.2",
 "rollup-plugin-commonjs": "^9.1.8",
}

Error:
default is not exported by ...

  1. commonjs-proxy: node_modules/core-js/library/modules/es6.object.to-string.js
    empty one :)
  2. commonjs-proxy: node_modules/react-lifecycles-compat/react-lifecycles-compat.es.js - this one has exporting:
    export { polyfill };

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants