我最近将我的 Ionic2 项目从 2.0.0-beta.11
更新到 2.0.0-rc.0
。我正在使用 Immutable.js(版本 ^3.8.1)。自更新以来,我在 Ionic Serve 命令期间遇到以下错误:
[16:50:23] bundle dev started ...
[16:50:40] Error: Module /myproject/node_modules/immutable/dist/immutable.js does not export Map (imported by /myproject/.tmp/effects/catalog.effects.js)
at Module.trace (/myproject/node_modules/rollup/dist/rollup.js:7677:29)
at ModuleScope.findDeclaration (/myproject/node_modules/rollup/dist/rollup.js:7300:22)
at Scope.findDeclaration (/myproject/node_modules/rollup/dist/rollup.js:5351:39)
at Scope.findDeclaration (/myproject/node_modules/rollup/dist/rollup.js:5351:39)
at Scope.findDeclaration (/myproject/node_modules/rollup/dist/rollup.js:5351:39)
at Scope.findDeclaration (/myproject/node_modules/rollup/dist/rollup.js:5351:39)
at CallExpression.bind (/myproject/node_modules/rollup/dist/rollup.js:5826:28)
at /myproject/node_modules/rollup/dist/rollup.js:5151:50
at ReturnStatement.eachChild (/myproject/node_modules/rollup/dist/rollup.js:5168:5)
at ReturnStatement.bind (/myproject/node_modules/rollup/dist/rollup.js:5151:7)
我不知道是否需要在我的 app.module.ts 文件中添加一些内容。我可能错过了一些东西。
谢谢。
最佳答案
如果不了解有关您的项目和设置的更多信息,就很难确切地知道问题和解决方案是什么、错误消息......
Error: Module /myproject/node_modules/immutable/dist/immutable.js does not export Map
...给我们提供了线索。 That file是一个 UMD 模块,默认情况下 Rollup 只理解 JavaScript 模块(带有 import
/export
声明)。我们可以使用 rollup-plugin-commonjs 对其进行转换,但在这种情况下,需要一个额外的步骤,因为 Rollup 无法在不实际运行代码的情况下知道 Immutable 有一个名为 Map
的导出。 (在某些情况下,它会弄清楚 - 当模块具有例如 exports.foo = bar
时,它会添加一个命名的 foo
导出,但 Immutable 的做法有所不同。 )
因此,我们通过使用 rollup-plugin-commonjs 中的 namedExports
选项来帮助它:
plugins: [
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/immutable/dist/immutable.js': [ 'Map', 'Set', ... ]
}
}),
...
]
这是不幸但必要的,因为 CommonJS 模块的语义与 ES 模块根本不同。
关于angular - immutable.js 不导出 Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39834709/