繁体   English   中英

Pouchdb Angular2 Webpack问题

[英]Pouchdb Angular2 webpack issue

我正在使用Jasmine 2.5,Webpack 2.2.1和karma 1.3.0对Angular 2提供程序进行单元测试...

我已经在ionic项目中使用了我的提供程序,并使用ionic app-scripts构建了它,一切正常。

但是,当我尝试使用角度webpack流程构建它时,出现了问题

我使用Pouchdb,并且其构造函数翻译错误,并且发生了错误。

未处理的承诺拒绝:pouchdb_browser_1.default不是构造函数; 区域:ProxyZone; 任务:Promise.then; 值:TypeError:pouchdb_browser_1.default不是构造函数

如果我进行构建,则使用构建后的过程代码将pouchdb_browser_1.default更改为pouchdb_browser可以正常工作。

不幸的是,我无法更改将在测试期间执行的代码。

请看下面我的webpack.test.js

const helpers = require('./helpers'),
webpack = require('webpack'),
LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); `module.exports = {

devtool: 'inline-source-map',



resolve: {
    extensions: ['.ts', '.js'],
    modules: [helpers.root('src'), 'node_modules']
},

module: {
    rules: [{
        enforce: 'pre',
        test: /\.ts$/,
        loader: 'tslint-loader',
        exclude: [helpers.root('node_modules')]
    }, {
        enforce: 'pre',
        test: /\.js$/,
        loader: 'source-map-loader',
        exclude: [
            // these packages have problems with their sourcemaps
            helpers.root('node_modules/rxjs'),
            helpers.root('node_modules/@angular')
        ]
    }, {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader',
        query: {
            // use inline sourcemaps for "karma-remap-coverage" reporter
            sourceMap: false,
            inlineSourceMap: true,
            module: "commonjs",
            removeComments: true
        },
        exclude: [/\.e2e\.ts$/]
    }, {
        enforce: 'post',
        test: /\.(js|ts)$/,
        loader: 'istanbul-instrumenter-loader',
        include: helpers.root('src'),
        exclude: [/\.spec\.ts$/, /\.e2e\.ts$/, /node_modules/]
    }],
},

plugins: [
    // fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
    new webpack.ContextReplacementPlugin(
        /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
        helpers.root('./src')
    ),

    new LoaderOptionsPlugin({
        debug: true,
        options: {

            /**
             * Static analysis linter for TypeScript advanced options configuration
             * Description: An extensible linter for the TypeScript language.
             *
             * See: https://github.com/wbuchwalter/tslint-loader
             */
            tslint: {
                emitErrors: false,
                failOnHint: false,
                resourcePath: 'src'
            },

        }
    })
]};

有任何想法吗 ?

谢谢 !

听起来像是将CommonJS转换为ES6模块的问题。 您是否以推荐的TypeScript方式导入PouchDB,例如这样?

import * as PouchDB from 'pouchdb';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM