jvandemo / generator-angular2-library

Yeoman generator to create an Angular library
MIT License
752 stars 122 forks source link

No name was provided for external module in rollup:umd task #272

Open sdwallace opened 6 years ago

sdwallace commented 6 years ago

I am getting these 'errors' when I run 'npm run build'. They seem to be warnings as everything works when I use the library but I would like to fix these.

No name was provided for external module '@angular/core' in options.globals - guessing 'core'
No name was provided for external module '@angular/common' in options.globals - guessing 'common'
No name was provided for external module '@angular/router' in options.globals -guessing 'router'
No name was provided for external module 'rxjs/Observable' in options.globals -guessing 'Observable'
No name was provided for external module 'rxjs/Subject' in options.globals - guessing 'Subject'
No name was provided for external module '@angular/platform-browser' in options.globals - guessing 'platformBrowser'
No name was provided for external module '@angular/forms' in options.globals - guessing 'forms'

Can anyone give me guidance?

Here is what my complete gulp task looks like. I changed the task a little as rollup was warning me of some config changes:

gulp.task('rollup:umd', function () {
  return gulp.src(`${buildFolder}/**/*.js`)
  // transform the files here.
    .pipe(rollup({

  // Bundle's entry point
  // See "input" in https://rollupjs.org/#core-functionality
  input: `${buildFolder}/index.js`,

  // Allow mixing of hypothetical and actual files. "Actual" files can be files
  // accessed by Rollup or produced by plugins further down the chain.
  // This prevents errors like: 'path/file' does not exist in the hypothetical file system
  // when subdirectories are used in the `src` directory.
  allowRealFiles: true,

  // A list of IDs of modules that should remain external to the bundle
  // See "external" in https://rollupjs.org/#core-functionality
  external: [
    '@angular/core',
    '@angular/platform-browser',
    '@angular/common',
    '@angular/forms',
    '@angular/router',
    'rxjs/Observable',
    'rxjs/Subject'
  ],

   output: {
        // Format of generated bundle
        // See "format" in https://rollupjs.org/#core-functionality

      format: 'umd',

      // Export mode to use
      // See "exports" in https://rollupjs.org/#danger-zone
      exports: 'named',

      // The name to use for the module for UMD/IIFE bundles
      // (required for bundles with exports)
      // See "name" in https://rollupjs.org/#core-functionality
      name: 'vueframework',

      // See "globals" in https://rollupjs.org/#core-functionality
      globals: {
        typescript: 'ts'
      }       
  },

}))
.pipe(rename('vueframework.umd.js'))
.pipe(gulp.dest(distFolder));

});

caroso1222 commented 6 years ago

It might be complaining because you're not giving names to those externals in the output.globals prop. Try this:

gulp.task('rollup:umd', function () {

  const rollupGlobals = {
    '@angular/core': 'ng.core',
    '@angular/platform-browser': 'ng.platformBrowser',
    '@angular/common': 'ng.common',
    '@angular/forms': 'ng.forms',
    '@angular/router': 'ng.router',
    'rxjs/Observable': 'Rx.Observable',
    'rxjs/Subject': 'Rx.Subject',
    'typescript': 'ts'
  }

  return gulp.src(`${buildFolder}/**/*.js`)
  // transform the files here.
    .pipe(rollup({

  // Bundle's entry point
  // See "input" in https://rollupjs.org/#core-functionality
  input: `${buildFolder}/index.js`,

  // Allow mixing of hypothetical and actual files. "Actual" files can be files
  // accessed by Rollup or produced by plugins further down the chain.
  // This prevents errors like: 'path/file' does not exist in the hypothetical file system
  // when subdirectories are used in the `src` directory.
  allowRealFiles: true,

  // A list of IDs of modules that should remain external to the bundle
  // See "external" in https://rollupjs.org/#core-functionality
  external: Object.keys(rollupGlobals),

   output: {
        // Format of generated bundle
        // See "format" in https://rollupjs.org/#core-functionality

      format: 'umd',

      // Export mode to use
      // See "exports" in https://rollupjs.org/#danger-zone
      exports: 'named',

      // The name to use for the module for UMD/IIFE bundles
      // (required for bundles with exports)
      // See "name" in https://rollupjs.org/#core-functionality
      name: 'vueframework',

      // See "globals" in https://rollupjs.org/#core-functionality
      globals: rollupGlobals          
  },

}))
.pipe(rename('vueframework.umd.js'))
.pipe(gulp.dest(distFolder));
});
sdwallace commented 6 years ago

Thanks @caroso1222 but after making that change, I still get the same warnings. I am noticing that the warning says "options.globals" vs "output.globals". Should I still this definition in a different place?