Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

webpack2 code split error with import when use extract-text-webpack-plugin #406

Closed
changfuguo opened this issue Feb 14, 2017 · 7 comments
Closed

Comments

@changfuguo
Copy link

changfuguo commented Feb 14, 2017

when use code split with import in webpack2 , we can get the error, when remove import and use synchronous method to load page, the error disapper

envrioment

extract-text-webpack-plugin: 2.0.0-rc.3

webpack: 2.2.1

os: mac os 10

node:6.4

webpack.config.js

const webpackBaseConfig = {

    context: basePath,
    
    entry: entriesConfig,
    
    output: {
        filename: "[name].[hash:8].js",
        //publicPath:'/'
    }, 
    
    plugins: [
        new ExtractTextPlugin({
            filename: '[name].[contenthash].css', 
            allChunks: true,
            disable: false
        }),
        //Enables Hot Modules Replacement
        new webpack.HotModuleReplacementPlugin(),
        new TransferWebpackPlugin([
            {from: 'static/static/images', to: 'static/images'},
            {from: 'static/static/js', to: 'static/js'},
            {from: 'static/static/html', to: 'static/html'},
            {from: 'static/static/views', to: 'static/views'}
        ], sourcePath),
        new webpack.LoaderOptionsPlugin({
            debug: false
        }),
        new webpack.NamedModulesPlugin()
     ],
    resolve: {
        modules: [
            basePath,
            "node_modules"
        ],
        extensions: [".js", ".json", ".jsx", ".css"],
    },
    module: {
        rules: [
            {
                test: /\.js$/,  
                exclude: [nodeModulesPath],
                include:[sourcePath],
                loader: 'babel-loader',
                options: {
                    presets: ['react', ['es2015', { "modules": false }], 'stage-0']
                }
            },
            { 
                test: /\.css$/, 
                use: [{
                    loader: 'style-loader'
                }, {
                    loader: 'css-loader'
                }] 
            },
            {
                test: /\.(png|jpg|eot|svg|ttf|woff|woff2)$/, 
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 4000
                    }
                }]
            },
            {
                test: /\.scss$/, 
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: [{
                        loader: 'css-loader'
                    }, {
                        loader: 'sass-loader'
                    }]
                })
            }
        ]
    },
};

routes.js

/**
* @file index route for index.js
*/
import React from 'react'
import {Router, Route, IndexRoute} from 'react-router'
import App from '../pages/app'
import Main from '../pages/main'

const getComponentLazily = (importor, name = 'default') => {
  return (location, cb) => {
    importor.then((module) => {
      //如果是默认模块,则是 module.default
      cb(null, module[name]);
    })
      .catch((err) => {
        console.error(`动态路由加载失败:${err}`)
      });
  }
};

var getRouters = (props) =>{

	return (
		<Router {...props}  > 
			<Route path="/" component={App}>
			    <IndexRoute component={Main}/>
			    <Route path="/organization" getComponent={getComponentLazily(import('../../public_module/pages/organization'))}/>
			</Route>
		</Router>
	)
	
}
export default getRouters;


result

TypeError: Cannot read property 'isInitial' of undefined
at ExtractTextPlugin. (/testuser/node_modules/extract-text-webpack-plugin/index.js:28:8)
at Array.forEach (native)
at ExtractTextPlugin.mergeNonInitialChunks (/testuser/node_modules/extract-text-webpack-plugin/index.js:27:16)
at ExtractTextPlugin. (/testuser/node_modules/extract-text-webpack-plugin/index.js:295:12)
at Array.forEach (native)
at ExtractTextPlugin. (/testuser/node_modules/extract-text-webpack-plugin/index.js:293:21)
at /testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:356:16
at iteratorCallback (/testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:936:13)
at /testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:840:16
at /testuser/node_modules/extract-text-webpack-plugin/index.js:289:6
at /testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:356:16
at iteratorCallback (/testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:936:13)
at /testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:840:16
at /testuser/node_modules/extract-text-webpack-plugin/index.js:286:13
at /testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:3025:16
at eachOfArrayLike (/testuser/node_modules/extract-text-webpack-plugin/node_modules/async/dist/async.js:941:9)

@changfuguo changfuguo changed the title webpack2 code split error when use extract-text-webpack-plugin webpack2 code split error with import when use extract-text-webpack-plugin Feb 14, 2017
@bebraw bebraw added this to the 2.1 features/fixes milestone Feb 19, 2017
@changfuguo
Copy link
Author

changfuguo commented Mar 28, 2017

does this problem be solved in 2.1, i just update my version to 2.1, but the problem still exists~?

@bebraw
Copy link
Contributor

bebraw commented May 6, 2017

This could use a minimal standalone example to help with debugging.

@alexander-akait
Copy link
Member

alexander-akait commented May 16, 2017

@Timer can your provide here minimal reproducible test repo?

@alexander-akait
Copy link
Member

alexander-akait commented Aug 18, 2017

Seems this solved in new version. Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!

@thedamon
Copy link

I'm getting this error thrown when trying to use the Vue-loader in my dev environment and I'm trying to track down why it's happening. Wondering what this might involve/be caused by.

@alexander-akait
Copy link
Member

@thedamon feel free to create new issue with minimum reproducible test repo, thanks!

@thedamon
Copy link

thedamon commented Sep 18, 2017

We'll see if I can manage to figure it out.. our build process is a bit complex.. I'm working on isolating what's necessary. So far it seems to build fine using webpack, but fails in our server process that uses webpack-dev-middleware.

webpack(siteConfigs, (err, stats) <== works
webpackMiddleware(webpack(siteConfigs, (err, stats)) <== doesn't work

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

No branches or pull requests

6 participants