webpack: Compiler.js TypeError: Function has non-object prototype 'null' in instanceof check
when I const webpack = require(‘webpack’); const compiler = webpack(CONFIG); console.log(compiler);
it can not console.log; and it has a error: TypeError: Function has non-object prototype ‘null’ in instanceof check
Then I debug in wepack/lib/Compiler.js:
// wepack/lib/Compiler.js
class Compiler {
/**
* @param {string} context the compilation path
*/
constructor(context) {
this.hooks = Object.freeze({
/** @type {SyncHook<[]>} */
initialize: new SyncHook([]),
// shouldEmit: new SyncBailHook(["compilation"]),
// done: new AsyncSeriesHook(["stats"]),
.......
});
console.log(this)
}
.........
}
it tell me that TypeError: Function has non-object prototype ‘null’ in instanceof check;
so next, I find path: webpack/node_modules/tapable/lib/SyncHook.js, Comment out this line of code
........
function SyncHook(args = [], name = undefined) {
const hook = new Hook(args, name);
hook.constructor = SyncHook;
hook.tapAsync = TAP_ASYNC;
hook.tapPromise = TAP_PROMISE;
hook.compile = COMPILE;
return hook;
}
// SyncHook.prototype = null;
module.exports = SyncHook;
it worked, Results printing:
Compiler {
hooks: {
initialize: Hook {
_args: [],
name: undefined,
taps: [],
interceptors: [],
_call: [Function: CALL_DELEGATE],
call: [Function: CALL_DELEGATE],
_callAsync: [Function: CALL_ASYNC_DELEGATE],
callAsync: [Function: CALL_ASYNC_DELEGATE],
_promise: [Function: PROMISE_DELEGATE],
promise: [Function: PROMISE_DELEGATE],
_x: undefined,
compile: [Function: COMPILE],
tap: [Function: tap],
tapAsync: [Function: TAP_ASYNC],
tapPromise: [Function: TAP_PROMISE],
constructor: [Function: SyncHook]
}
}
}
I think it is bug, the same to:
SyncHoo.js
SyncBailHook.js
AsyncParallelHook.js
AsyncSeriesHook.js
AsyncSeriesBailHook.js
webpack version: 5.1.3 Node.js version: v14.14.0 Operating System: mac Additional tools:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (13 by maintainers)
The related issue in node.js: https://github.com/nodejs/node/issues/35730
是 node 的问题,我升级到最新的 14.16.1,就不会报错了。 It’s a nodejs problem, I upgraded to 14.16.1 version, no error will be reported.
I have the same issue here. When i just create a simple webpack plugin and do
console.log(compiler)
inapply
method ."webpack": "^5.9.0"
"webpack-cli": "^4.2.0"
Node version: v14.15.1
And the error is :
Fixed in
10
/12
/15
, for14
here commit https://github.com/nodejs/node/commit/f206505e9d59b072de552310264ab4c3e8a361c5, nothing to fix on our sideNo
Because we rely on JS behaviour and here Node.js has bug