我是第一次使用Rollup(紧跟在angular.io的示例之后),并且出现了这个错误:

'AuthHttp'不是由'node_modules/angular2-jwt/angular2-jwt.js'导出的

从app.module.js中的这一行开始:

13:从'angular2-jwt/angular2-jwt'导入{AuthHttp,AuthConfig};

文档说您可以通过在rollup-config.js文件中指定一个名为export的自定义名称来纠正此问题,如下所示:

commonjs({
  namedExports: {
    // left-hand side can be an absolute path, a path
    // relative to the current directory, or the name
    // of a module in node_modules
    'node_modules/my-lib/index.js': [ 'named' ]
  }
})

这是我的rollup-config.js文件的相关部分:
  plugins: [
      nodeResolve({jsnext: true, module: true}),
      commonjs({
        include: 'node_modules/rxjs/**',
         namedExports: {
          'node_modules/angular2-jwt/angular2-jwt.js': [ 'AuthHttp' ]
        }
      }),

但是,这没有任何效果,并且错误仍然存​​在。关于如何更正此问题的任何建议?

最佳答案

试试这个,让我知道你的情况:

rollup-config.js

commonjs({ include: ['node_modules/rxjs/**',
                     'node_modules/angular2-jwt/angular2-jwt.js'],
 ..
         })

您也做了npm i -D rollup-plugin-node-resolve吗?

jsnext显示在rollup-plugin-node-resolve文档中
here

issues中也有一个关于在下一个版本中删除它的神秘评论。

但是,rollup wiki docs对于 jsnext 似乎也很奇怪。
他们只是说它已被pkg.module取代,而starter-project并不能真正为我澄清事情。因此,也许删除标志或切换为假

有一个汇总rollup-starter-lib配置文件。它在目标数组中引用了 pkg.module

还有一个guide配置示例。

这是汇总rollup-plugin-commonjs

更新:

命名导出似乎是here的一部分npm i -D rollup-plugin-commonjs

`// explicitly specify unresolvable named exports
 // (see below for more details)
 namedExports: { './module.js': ['foo', 'bar' ] },  // Default: undefined`

您是否也按照ojit_a正确设置了 tsconfig-aot.json

关于angular - 汇总中的自定义命名导出不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45406552/

10-16 19:43