webpack-contrib / webpack-hot-middleware

Webpack hot reloading you can attach to your own server
MIT License
2.34k stars 296 forks source link

Get error when use fileSystem.readFileSync #198

Closed dxcqcv closed 2 years ago

dxcqcv commented 7 years ago
// webpack.config.js
var path = require( "path" );
var webpack = require( 'webpack' );

module.exports = {
  entry: {
    app: [ "webpack-hot-middleware/client?reload=1", "./src/main.js" ]
  },
  output: {
    path: path.resolve( __dirname, 'dist' ),
    publicPath: "/assets/",
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      }
    ]
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
  ]
};
// app.js
require( "babel-polyfill" );
var webpack = require( 'webpack' )
var koaWebpack = require('koa-webpack');
var webpackConf = require( './webpack.config' )
var Koa = require( 'koa' )
var app = new Koa()
var compiler = webpack( webpackConf );
var middleware = koaWebpack({
  compiler:compiler , 
  dev:{
  noInfo: false,
  publicPath: webpackConf.output.publicPath
} 
}) 
app.use( middleware  )
app.use( ctx => {
  console.log(middleware.dev.fileSystem);
  const htmlBuffer = middleware.dev.fileSystem.readFileSync(`./index.html`);
  ctx.type = 'html';
  ctx.body = htmlBuffer; 
} )
app.listen( 3000 );

Expected Behavior

just rebuild html files in stream but do not need press F5 when change index.html

Actual Behavior

get error

MemoryFileSystem { data: { home: { '': true, clyde: [Object] } } }

  Error
      at pathToArray (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/memory-fs/lib/MemoryFileSystem.js:44:10)
      at MemoryFileSystem.readFileSync (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/memory-fs/lib/MemoryFileSystem.js:103:13)
      at app.use.ctx (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/app.js:37:48)
      at dispatch (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/koa-compose/index.js:44:32)
      at next (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/koa-compose/index.js:45:18)
      at dispatch (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/koa-compose/index.js:44:32)
      at next (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/koa-compose/index.js:45:18)
      at middleware (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/webpack-hot-middleware/middleware.js:26:48)
      at _callee2$ (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/koa-webpack/dist/index.js:127:22)
      at tryCatch (/home/clyde/Desktop/temp/ygm125/webpack/demo/webpack-hot-middleare/node_modules/regenerator-runtime/runtime.js:64:40)

How can we reproduce the behavior?

git clone https://github.com/dxcqcv/koa-demo.git then run node app.js in that

webpack-hot-middleare/app.js:37

emma-dan-guo commented 5 years ago

Finally, how do you solve this problem?

alexander-akait commented 2 years ago

Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!