"参数'模块'不是一个功能,得到了对象" - 使用webpack

时间:2018-02-28 08:22:30

标签: javascript angularjs webpack es6-modules angular-formly

我在angular 1.x app中使用webpack和ES6模块。在webpack.config中我设置:

resolve: {
  alias: {
    'angular': 'angular/angular',
    'angularFormly': 'angular-formly/dist/formly',
    'apiCheck': 'api-check/dist/api-check',
    'formlyAngularTemplatesBootstrap': 'angular-formly-templates-bootstrap/dist/angular-formly-templates-bootstrap'
  }
}

module: {
  loaders: [
    { test: /angular/, loader: 'exports-loader?angular' },
    { test: /apiCheck/, loader: '!imports-loader?angular' },
    { test: /angularFormly/, loader: '!imports-loader?angular,apiCheck' },
    { test: /formlyAngularTemplatesBootstrap/, loader: '!imports-loader?angular,angularFormly' },
  ]
}

现在在JS文件中创建模块:

import 'angularFormly';
import 'formlyAngularTemplatesBootstrap';

export const FormlyUtilityModule = angular
  .module('formly-utility', [
    'formly',
    'formlyBootstrap'
  ])
  .name;

不幸的是我收到了错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module formly-utility due to:
Error: [$injector:modulerr] Failed to instantiate module formlyBootstrap due to:
Error: [$injector:modulerr] Failed to instantiate module {"version":{"full":"1.5.8","major":1,"minor":5,"dot":8,"codeName":"arbitrary-fallbacks"},"callbacks":{}} due to:
Error: [ng:areq] Argument 'module' is not a function, got Object

任何想法为什么&formlyBootstrap'没有用?

2 个答案:

答案 0 :(得分:0)

也许试试这个:

ForwardIt2

答案 1 :(得分:0)

你是否尝试过棱角分明的自述文件的第二种方式?

export const FormlyUtilityModule = angular.module('formly-utility', [
  require('angular-formly'),
  require('angular-formly-templates-bootstrap')
]).name;