javascript - 为什么 webpack 打包时不包含 assert.rejects(UMD 库目标)
问题描述
如果您愿意,可以将此 repo 作为起点: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)
解决方案
asserts.rejects
仅在 NodeJS v10.x 及更高版本中可用。
推荐阅读
- c# - 如何检查字典中的重复值
- printing - wkhtmltopdf 打破网格模板
- python - AttributeError:“窗口”对象没有“按下”属性
- python - timeit(缓存问题?)导致不可靠(?)
- android - ANDROID_ID 在 Android 清单文件中需要一些特定权限吗?
- javascript - 表单提交触发无头 UI 元素打开
- python - 我可以在excel单元格中编写一行代码然后将其导入python吗?
- visual-studio-code - 如何防止 vs 代码不访问我的所有文件
- c# - 如何在 ASP.NET MVC 中自动更改用户角色
- android - 如何在博览会中更改targetsdkversion android api级别?