如果您愿意,可以将此仓库用作起点:https://github.com/goofballLogic/webpackery
我的代码运行一个断言
const assert = require( "assert" );
assert.rejects( () => Promise.reject() );
传入node.js。
当我使用webpack捆绑此代码并从节点(例如,在浏览器中)运行时,会产生以下输出。为什么?
> ./node_modules/.bin/webpack-cli --entry ./test.js --output test.bundle.js --libraryTarget umd --mode development
Hash: d30ba0b02040a574f117
Version: webpack 4.33.0
Time: 200ms
Built at: 06/12/2019 10:50:56
Asset Size Chunks Chunk Names
test.bundle.js 51.8 KiB null [emitted] null
Entrypoint null = test.bundle.js
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {null} [built]
[./test.js] 78 bytes {null} [built]
+ 6 hidden modules
> node test.js
webpack:///./test.js?:2
assert.rejects( () => Promise.reject() );
^
TypeError: assert.rejects is not a function
at eval (webpack:///./test.js?:2:8)
at Object../test.js (/Users/andrewgibson/src/webpackery/test.bundle.js:175:1)
at __webpack_require__ (/Users/andrewgibson/src/webpackery/test.bundle.js:20:30)
at /Users/andrewgibson/src/webpackery/test.bundle.js:84:18
at Object.<anonymous> (/Users/andrewgibson/src/webpackery/test.bundle.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
答案 0 :(得分:0)
asserts.rejects
仅在NodeJS v10.x及更高版本中可用。