Closed notiv-nt closed 4 years ago
Please create minimum reproducible test repo, i think you have something wrong in setup, you should not run webpack twice as error said
this is the problem that everything works in the "minimal version" but ill try
I think i found it https://github.com/notiv-nt/webpack-dev-lazy
yarn start
open localhost:8090
open console, and paste
fetch('/bundle.js');fetch('/bundle.js');
error appears when a file is requested 2 times at the same time, but in the work, in the docker container, I cannot control requests, although only a bundle.js is requested.
Why you use lazy? Can you describe use case?
hmr too heavy + there are multiple client's if I start all services at the beginning (hmr), and not on request, everything will very slow down
hm, looks like a bug, feel free to send a PR
Not sure, i think problem deeply, need investigate
I dont know, but just placing this code inside process.nextTick
solves this problem.
I've tested
is bundle.js
the one you are requesting is present in your public folder cause in the repo you mentioned its not there and It seems an error is obvious if its not there which is happening. I tried to repro the case and I placed bundle.js inside the public and its working fine.
@anikethsaha bundle.js — webpack's output file
That is quite obivious after seeing your config file. But what I meant was its not been created after running your repo. If its help can you manually create that and check. I knw it sud be created automatically but for just for test being can you do that
@anikethsaha
I meant was its not been created after running your repo
Because its webpack's bundlee file, what should it do in public
?
If its help can you manually create that and check
what is it for? the problem is generally in compilation
Actually weirdly it was not creating. And I think it's not in compilation it's in the fetch argument. Let's wait for others and discuss this in the PR to see if it workout.
@anikethsaha yep, it is invalid solution, we should search other way to solve this problem, any ideas?
I don’t understand what you are saying. Your plugin crashes. What is the public folder? What are you talking about? The problem in COMPILATION
ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.
Actually weirdly it was not creating
This is dev server. And this file should not be created in public
This is dev server
oops .. my bad 😁 I couldn't able to reproduce the error, it's surely something to do with Docker as you mentioned ! am not much into docker, so I am not really able to debug it
The problem in COMPILATION
I meant problem is in the env which is leading to this error
Ok, same error without docker.
<script>
fetch('/bundle.js');
fetch('/bundle.js');
</script>
I dont know how and where, but in real project i have only one entry file
<script src="/assets/js/bundle.js"></script>
But the same error appears, possibly due to the multitude of asynchronous modules
@notiv-nt it is appears only in docker, right?
Deleting these 4 lines solves the problem for me. I do not know how for others
if (context.forceRebuild) {
context.forceRebuild = false;
rebuild();
}
https://github.com/webpack/webpack-dev-middleware/issues/409#issuecomment-504957820 It's working fine for me, !!!!
I want clarify what it is happens only in docker, somebody can give feedback?
@evilebottnawi not only in docker
➜ webpack-dev-lazy git:(master) yarn start
yarn run v1.16.0
warning package.json: No license field
$ ./node_modules/.bin/webpack-dev-server --config webpack.config.js
ℹ 「wds」: Project is running at http://localhost:8090/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /Users/nt/Documents/GitHub/webpack-dev-lazy/public
ℹ 「wdm」: wait until bundle finished: /bundle.js
ℹ 「wdm」: wait until bundle finished: /bundle.js
ℹ 「wdm」: wait until bundle finished: /favicon.ico
✖ 「wdm」: ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.
at Compiler.run (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack/lib/Compiler.js:211:37)
at rebuild (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack-dev-middleware/lib/context.js:81:24)
at done (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack-dev-middleware/lib/context.js:59:7)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:18:1)
at AsyncSeriesHook.lazyCompileHook (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/tapable/lib/Hook.js:154:20)
at emitRecords.err (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack/lib/Compiler.js:267:22)
at Compiler.emitRecords (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack/lib/Compiler.js:449:39)
at emitAssets.err (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack/lib/Compiler.js:261:10)
at hooks.afterEmit.callAsync.err (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/webpack/lib/Compiler.js:435:14)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nt/Documents/GitHub/webpack-dev-lazy/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
@notiv-nt is your src/index.js is having some content or its just empty as in the repo you mentioned ?
1:1 like in repo
const path = require('path');
module.exports = {
context: path.resolve(__dirname, './'),
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: '/',
},
devServer: {
port: 8090,
contentBase: path.resolve(__dirname, 'public'),
lazy: true,
filename: 'bundle.js',
},
};
'empty'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
fetch('/bundle.js');
fetch('/bundle.js');
</script>
</body>
</html>
Its still working fine on my system
Try to reload without cache ctrl+shift+r
, if not, i dont know
I did with clearing the cache already but it was working fine. Now I am on windows edge and Now the error is coming
I would add this
(async function(){
await fetch('/bundle.js');
await fetch('/bundle.js');
})()
just to handle the requests Although not sure about the error type, I guess it should not be of type compilation error.
How did you fix this? @notiv-nt
@notiv-nt Still I got the same error
@KathiresanRamkumar95 ¯\_(ツ)_/¯
i havent
The issue resolved itself by downgrading to ^3.1.14 instead of the latest version. Seems something changed in between those versions.
must be the api webpack of webpack4 is async,you should change the devmidware into callback
I encouter the same error, when I use webpack-dev-middleware with lazy: true
option and webpack-hot-middleware.
When a request come in, the value of context.state
is false, and its hooks.done called before the last request's done hook, and the error occur. In my case the error always found between /__webpack_hmr
and /app.bundle.js.map
request.
Put the code below in the bottom of the process.nextTick callback function, can solve my problem.
// webpack-dev-middleware/context.js
if (context.forceRebuild) {
context.forceRebuild = false;
rebuild(callback);
}
The reason may be the webpack compiler process.nextTick callback could wait for finalCallback called.hooks.done
is a Hook type of AsyncSeriesHook
. And wdm tap the hook, context.compiler.hooks.done.tap('WebpackDevMiddleware', done)
, so
// webpack/Compiler.js
const finalCallback = (err, stats) => {
this.running = false;
// ...
})
this.hooks.done.callAsync(stats, err => {
if (err) return finalCallback(err);
return finalCallback(null, stats);
});
PR welcome, also we need test(s)
No need PR, lazy
will be removed in next release, it is incompatibility approach for webpack and middleware
lazy was removed for next release
When is the next release expected to come out?
I got the same question when I use the webpack-dev-server boot my project
` [webpack-dev-middleware] ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.
at Compiler.watch (C:\Users\worker\Desktop\zzy\package\test\node_modules\webpack\lib\Compiler.js:411:19)` My code: ` **complier.run((err,stat)=>{ err && console.log(err) })** let ServerConfig:ServerConfiguration = { host:"127.0.0.1", port:3000, hot:true, open:false, } const devServer = new WebpackDevServer(ServerConfig,complier) devServer.start() devServer.stopCallback(()=>{ console.log("serverstop") })` stack top info ----I use complier twice ,so I check my code find the "complier.run((err,stat)=>{ err && console.log(err) }) " is extra . just delete it .
I am also getting the error:
ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.
when I run 2, or more, Webpack configurations as described here.
I use webpack serve
and I see it each time.
All the configuration are running on the same project, but with different bundle builds configurations.
@nisimjoseph Can you creatre reproducible test repo?
I get this error with webpack 5, dev server 4. Here's a reproduction:
git clone git@github.com:lume/harp-terrain-datasource.git
cd harp-terrain-datasource
git checkout webpack-issue-409
cd example
npx yarn install
npx yarn start # shows error in the output
@trusktr There are no problems with webpack-dev-middleware, problems with CLI and dev server, we have an issue about it
Context
docker, webpack-dev-server , lazy: true
Error itself:
https://github.com/webpack/webpack/blob/master/lib/Compiler.js#L211
I still can not find the reason for this error, its very hard to catch, but found a solution:
https://github.com/notiv-nt/webpack-dev-middleware/commit/9a7ce044682aca870061f7352377c4fdc8545ff8
https://github.com/webpack/webpack-dev-middleware/blob/9f8f9471411ddf9e882f7c83c85325b5cb324216/lib/context.js#L57-L60
This code throws an error, when I reload the page during the build, sure this lines are needed?