thread-loader
thread-loader copied to clipboard
build error or build hang with libuv 1.46
- Operating System: Arch Linux 6.4.4-arch1-1
- Node Version: 16.20.1
- NPM Version: 9.8.1
- webpack Version: 5.88.2
- thread-loader Version: 4.0.2
- libuv Version: 1.46
Expected Behavior
Webpack build builds successfully
Actual Behavior
Webpack build either hangs indifinetely or fails with the following 2 errors:
- JSON Parse failed unexpected token at random, each time, positions
- Error EPIPE
Code
// package.json
{
"name": "libuv-error-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"thread-loader": "^4.0.2",
"webpack": "^5.88.2"
},
"devDependencies": {
"ts-loader": "^9.4.4",
"typescript": "^5.1.6",
"webpack-cli": "^5.1.4"
}
}
// webpack.config.js
const path = require('path');
module.exports = {
mode: "development",
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'thread-loader',
},
{
loader: 'ts-loader',
options: {
happyPackMode: true,
experimentalWatchApi: true,
experimentalFileCaching: true,
}
}
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
// tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
}
}
// src/index.ts
import {component1} from './test1'
import {component2} from './test2'
import {component3} from './test3'
component1()
src/test1.ts
https://gist.github.com/JohnKoutsoumpas/de5b6f893f558c13dbd5b395b349b3c1
src/test2.ts
https://gist.github.com/JohnKoutsoumpas/1f7bae8f832198a25e5dd4f28420307f
src/test3.ts
https://gist.github.com/JohnKoutsoumpas/93a20cd27063bdce1a0fc53498fc4908
How Do We Reproduce?
create all the above files in an new empty dir, run npm i and then run node ./node_modules/webpack/bin/webpack.js and it will hang indefinitely (with libuv 1.46 installed). With libuv 1.44 it builds fine.
I filed a relevant issue with libuv too, they told me that this is a problem with the application (thread-loader).
Node.js released v18.18.0 where they switch to libuv 1.46, we also experienced an issue where jobs running thread-loader are hanging indefinitely or throw a JSON parse error.
We were getting this on v18.18.0 and have rolled back to v18.17.1 for now
#26 6.723 SyntaxError: Unexpected token in JSON at position 56
#26 6.723 at JSON.parse (<anonymous>)
#26 6.723 at /www/sites/base_web/node_modules/thread-loader/dist/WorkerPool.js:122:30
#26 6.723 at Socket.onChunk (/www/sites/base_web/node_modules/thread-loader/dist/readBuffer.js:32:9)
#26 6.723 at Socket.emit (node:events:517:28)
#26 6.723 at addChunk (node:internal/streams/readable:335:12)
#26 6.723 at readableAddChunk (node:internal/streams/readable:308:9)
#26 6.723 at Readable.push (node:internal/streams/readable:245:10)
#26 6.723 at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
#26 6.723
#26 6.723 Node.js v18.18.0
disable IO_URING usage in libuv by adding UV_USE_IO_URING=0 when running webpack build command solves the hang for me - I'm using node 18.18.0, which uses libuv 1.46.