gpt4 book ai didi

angular - 汇总和 Redux : "index.js does not export default"

转载 作者:搜寻专家 更新时间:2023-10-30 21:30:29 24 4
gpt4 key购买 nike

我已将我的 ionic 应用程序从 beta 11 更新到 rc0。所以这意味着我已经从 angular2 rc4 切换到 angular2 stable,从 typescript 1.8 切换到 2,并使用了 rollupjs 模块 bundler 。

我有一个 redux 架构并且正在使用 Redux 库。

我无法编译并收到此错误:

Error: Module c:\XXX\node_modules\redux\node_modules\symbol-observable\index.js does not export default (imported by c:\XXX\node_modules\redux\es\createStore.js)

at Module.trace (c:\XXX\node_modules\rollup\dist\rollup.js:7677:29)

at ModuleScope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:7300:22)

at Scope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:5351:39)

at Scope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:5351:39)

at Identifier.bind (c:\XXX\node_modules\rollup\dist\rollup.js:6489:29)

at c:\XXX\node_modules\rollup\dist\rollup.js:5151:50

at MemberExpression.eachChild (c:\XXX\node_modules\rollup\dist\rollup.js:5168:5)

at MemberExpression.bind (c:\XXX\node_modules\rollup\dist\rollup.js:5151:7)

at MemberExpression.bind (c:\XXX\node_modules\rollup\dist\rollup.js:6693:24)

at c:\XXX\node_modules\rollup\dist\rollup.js:5151:50

有人对发生的事情有任何想法吗?有人可以给我一些指示吗?我真的不明白如何处理这个问题。

这就是我在 rollup.config.js

中的内容
var ngTemplate = require('../dist/plugins/ng-template').ngTemplate;
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');

// https://github.com/rollup/rollup/wiki/JavaScript-API

module.exports = {
/**
* entry: The bundle's starting point. This file will
* be included, along with the minimum necessary code
* from its dependencies
*/
entry: './.tmp/app/main.dev.js',

/**
* sourceMap: If true, a separate sourcemap file will
* be created.
*/
sourceMap: true,

/**
* format: The format of the generated bundle
*/
format: 'iife',

/**
* dest: the output filename for the bundle in the buildDir
*/
dest: 'main.js',

// Add this to avoid Eval errors
useStrict: false,

/**
* plugins: Array of plugin objects, or a single plugin object.
* See https://github.com/rollup/rollup/wiki/Plugins for more info.
*/
plugins: [
ngTemplate(),
commonjs({
include: [
'node_modules/rxjs/**',
'node_modules/firebase/**',
'node_modules/angularfire2/**'
],
namedExports: {
'node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
}
}),
nodeResolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions: ['.js']
})
]

};

最佳答案

错误的第一部分...

Error: Module c:\XXX\node_modules\redux\node_modules\symbol-observable\index.js does not export default

...表示 symbol-observable\index.js 没有 export default 语句。那是因为它是一个 CommonJS 模块——它的全部内容如下:

module.exports = require('./lib/index');

因此您需要将其从 CommonJS 转换为 ES。您已经设置了 rollup-plugin-commonjs,所以希望这只是重新配置它的一个例子。目前,只有 rxjsfirebaseangularfire2 中的模块正在被转换。

通常最好只包括所有的 node_modules,因为这样你就不必手动包括像 symbol-observable 这样的 dependencies-of-dependencies:

plugins: [
ngTemplate(),
commonjs({
include: [
'node_modules/**'
],
namedExports: {
'node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
}
}),
nodeResolve(...)

node_modules 中的任何不是 CommonJS 的文件都将原封不动地通过插件。

关于angular - 汇总和 Redux : "index.js does not export default",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com