简体   繁体   English

为什么 webpack 在打包时不包含 assert.rejects(UMD 库目标)

[英]Why doesn't webpack include assert.rejects when bundling (UMD library target)

You can use this repo as a starting point if you wish: https://github.com/goofballLogic/webpackery如果你愿意,你可以使用这个 repo 作为起点: https : //github.com/goofballLogic/webpackery

My code runs an assertion我的代码运行断言

const assert = require( "assert" );
assert.rejects( () => Promise.reject() );

which passes in node.js.它传入 node.js。

When I bundle this code using webpack and run from node (or eg in a browser) it produces the following output.当我使用 webpack 捆绑此代码并从节点(或例如在浏览器中)运行时,它会产生以下输出。 Why?为什么?

> ./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 及更高版本中可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM