Skip to content

Error: More than a single candidate module was found in webpack stats for require()d path "!!.. #143

@fisherw

Description

@fisherw

The error was occured when I use require.ensure in my route.

webpack-isomorphic-tools config:

var path = require('path');
var WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin');

module.exports = {
    debug: true,
    assets: {
        images: {
            extensions: ['png', 'jpg', 'gif', 'ico', 'svg'],
            // parser: WebpackIsomorphicToolsPlugin.url_loader_parser,
        },
        html: {
			extension: 'html',
		},
		fonts: {
			extensions: ['woff', 'woff2', 'eot', 'ttf'],
            // parser: WebpackIsomorphicToolsPlugin.url_loader_parser,
		},
        styles: {
            extensions: ['css', 'scss'],
            // parser: WebpackIsomorphicToolsPlugin.url_loader_parser,
        },
    },

    // to resolve "TypeError: require.context is not a function" or "TypeError: require.ensure is not a function"
    patch_require: true,

    alias: {
        components: path.resolve(__dirname, './components'),
        actions: path.resolve(__dirname, './actions'),
        reducers: path.resolve(__dirname, './reducers'),
        comtainers: path.resolve(__dirname, './containers'),
        assets: path.resolve(__dirname, './assets')
    }
};

route config sample:

export const FreeRecommend = {
    path: 'free-recommend',
    getComponent: function(nextState, callback){
        require.ensure([], (require) => {
            callback(null, require('../containers/free-recommend'));
        });
    }
};

export const ChargeRecommend = {
    path: 'charge-recommend',
    getComponent: function(nextState, callback){
        require.ensure([], (require) => {
            callback(null, require('../containers/charge-recommend'));
        });
    }
};

webpack config:

module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader?cacheDirectory'
            },
            {
                test: webpack_isomorphic_tools_plugin.regular_expression('styles'),
                exclude: /node_modules/,
                // loaders: ["style", "css", "postcss", "sass"]
                use: extractCSS.extract({
                    fallback: 'style-loader',
                    use: [
                        'css-loader?-autoprefixer',
                        'postcss-loader',
                        'sass-loader?outputStyle=expanded',
                    ]
                })
            },
            {
                test: webpack_isomorphic_tools_plugin.regular_expression('images'),
                exclude: /node_modules/,
                use: 'url-loader?limit=8192&name=img/[name].[hash].[ext]', // inline base64 URLs for <=8k images
            },
            {
                test: webpack_isomorphic_tools_plugin.regular_expression('fonts'),
                exclude: /node_modules/,
                use: 'url-loader?limit=1024&name=fonts/[name].[hash].[ext]',
            },
            {
                test: /\.json/,
                use: 'json-loader',
            }
        ],
    },

error code:

[webpack-isomorphic-tools/plugin] [error] Error: More than a single candidate module was found in webpack stats for require()d path "!!../../../../node_modules/.0.25.0@css-loader/index.js?-autoprefixer!../../../../node_modules/.0.13.0@postcss-loader/index.js!../../../../node_modules/.6.0.6@sass-loader/lib/loader.js?outputStyle=expanded!./style.scss". Enable "debug: true" flag in webpack-isomorphic-tools configuration for more info.
    at fail (/Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:443:11)
    at /Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:451:5
    at resolver (/Users/fisher/myworkspace/frontend/node_modules/.2.1.4@require-hacker/babel-transpiled-modules/require hacker.js:140:17)
    at Function._module2.default._findPath (/Users/fisher/myworkspace/frontend/node_modules/.2.1.4@require-hacker/babel-transpiled-modules/require hacker.js:450:25)
    at Function.Module._resolveFilename (module.js:467:25)
    at Function._module2.default._resolveFilename (/Users/fisher/myworkspace/frontend/node_modules/.2.1.4@require-hacker/babel-transpiled-modules/require hacker.js:423:34)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/fisher/myworkspace/frontend/site/wechat-react/containers/wx-login/style.scss.webpack-module:5:15)
    at Module._compile (module.js:570:32)
    at Object._module2.default._extensions.(anonymous function) [as .webpack-module] (/Users/fisher/myworkspace/frontend/node_modules/.2.1.4@require-hacker/babel-transpiled-modules/require hacker.js:274:11)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at safe_require (/Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:563:10)
    at populate_assets (/Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:529:32)
    at write_assets (/Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:74:2)
    at Compiler.<anonymous> (/Users/fisher/myworkspace/frontend/node_modules/.2.6.6@webpack-isomorphic-tools/babel-transpiled-modules/plugin/plugin.js:213:45)
    at Compiler.applyPlugins (/Users/fisher/myworkspace/frontend/node_modules/.0.2.6@tapable/lib/Tapable.js:61:14)
    at Watching._done (/Users/fisher/myworkspace/frontend/node_modules/.3.0.0@webpack/lib/Compiler.js:100:16)
    at onCompiled (/Users/fisher/myworkspace/frontend/node_modules/.3.0.0@webpack/lib/Compiler.js:51:17)
    at /Users/fisher/myworkspace/frontend/node_modules/.3.0.0@webpack/lib/Compiler.js:516:13
    at next (/Users/fisher/myworkspace/frontend/node_modules/.0.2.6@tapable/lib/Tapable.js:138:11)
    at Compiler.<anonymous> (/Users/fisher/myworkspace/frontend/node_modules/.3.0.0@webpack/lib/CachePlugin.js:62:5)
    at Compiler.applyPluginsAsyncSeries (/Users/fisher/myworkspace/frontend/node_modules/.0.2.6@tapable/lib/Tapable.js:142:13)
    at /Users/fisher/myworkspace/frontend/node_modules/.3.0.0@webpack/lib/Compiler.js:513:10
    at Compilation.applyPluginsAsyncSeries (/Users/fisher/myworkspace/frontend/node_modules/.0.2.6@tapable/lib/Tapable.js:131:46)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions