node_modules \ ng2-dragula \ index.js不会导出“DragulaModule”

时间:2017-01-25 16:00:31

标签: javascript angular typescript rollup ng2-dragula

'DragulaModule' is not exported by node_modules\ng2-dragula\index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
app\app.module.js (13:9)
11: import { BrowserModule } from '@angular/platform-browser';
12: import { AppComponent } from './app.component';
13: import { DragulaModule } from 'ng2-dragula';
             ^
14: import { FileUploadModule } from "ng2-file-upload";

rollup.config.js

import rollup      from 'rollup'
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: 'dist/build.js',
  sourceMap: false,
  format: 'iife',
  plugins: [
      nodeResolve({jsnext: true, module: true}),
      commonjs({
        include: 'node_modules/rxjs/**',
      }),
      uglify()
  ]
}

在使用aot成功生成文件后,使用Rollup进行树抖动和构建会给出上述错误。任何建议都受到高度赞赏。

2 个答案:

答案 0 :(得分:0)

尝试在rollup.config中添加命名导出



commonjs({
      include: 'node_modules/rxjs/**',
      namedExports: {
        'node_modules/ng2-dragula/ng2-dragula.js': [ 'DragulaModule', 'DragulaService' ]
      }
    })




您可以在此处详细了解自定义命名导出:https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports

答案 1 :(得分:-1)

如果您使用角度6,
将此行添加到pollyfills.ts中解决了我的问题

(任意窗口).global = window;