2

我正在尝试构建一个 React 模块,然后在我的主应用程序中使用它,但是在使用它时我得到:

addComponentAsRefTo(...):只有 ReactOwner 可以有 refs。您可能正在向未在组件的 render 方法中创建的组件添加 ref,或者您加载了多个 React 副本。

这是我的 webpack AwesomeModule

const prodConfig = {
    entry: {
        'awesomeModule.js': './src/js/index.js'
    },
    output: {
        path: PATHS.distJs,
        filename: 'awesomeModule.js',
        libraryTarget: 'umd',
        library: 'AwesomeModule'
    },
    externals: {
        'react': 'React',
        'moment': 'moment',
        'lodash': 'lodash'
    },
    module: {
        loaders: [
            {
                test: /(\.jsx|\.js)$/,
                include: PATHS.src,
                loader: 'babel'
            },
            {
                test: /\.json$/,
                loader: 'json'
            },
            {
                test: /\.less$/,
                include: PATHS.src,
                loader: 'style-loader!css-loader!less-loader'
            }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '"production"'
        }),
        new AssetsPlugin({
            filename: 'assets.json',
            path: PATHS.distJs,
            fullPath: false,
            prettyPrint: true
        }),
        envParamsPlugin
    ]
};

在我的主应用程序中,我将它添加到dependencies我的package.json. 这是我的 webpack 配置App

const prodConfig = {
    entry: {
        'app.js': "./src/index.jsx"
    },
    output: {
        path: PATHS.distJs,
        filename: "app-[hash].js"
    },
    module: {
        loaders: [
            {
                test: /(\.jsx|\.js)$/,
                include: PATHS.src,
                loader: "babel"
            },
            {
                test: /\.json$/,
                loader: 'json'
            },
            {
                test: /\.less$/,
                include: PATHS.src,
                loader: 'style-loader!css-loader!less-loader'
            }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx'],
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '"production"'
        }),
        new AssetsPlugin({
            filename: 'assets.json',
            path: PATHS.distJs,
            fullPath: false,
            prettyPrint: true
        }),
        envParamsPlugin
    ]
};

我的问题在哪里?

4

0 回答 0