Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fisherw opened this issue Jun 25, 2017 · 2 comments

Comments

@fisherw
Copy link

fisherw commented Jun 25, 2017

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)
@catamphetamine
Copy link
Owner

catamphetamine commented Jun 25, 2017

It says that "!!../../../../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" is ambiguous.

First, find the places in your project where ./style.scss is required.
Second, the error message explicitly told you to enable debug: true and you still haven't done that.
Third, post your webpack-stats.json

@catamphetamine
Copy link
Owner

You could also see if the issue is present in [email protected].
I recently released a new version [email protected] which supports Webpack 3 breaking changes.
If this bug happens to only appear in the latest version of webpack-isomorphic-tools then it would narrow the search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants