使用 esbuild 的项目失败如下...
node_modules/htmlparser2/lib/Parser.js:133:36: error: Could not resolve "events" (set platform to "node" when building for node)
require("inherits")(Parser, require("events").EventEmitter);
~~~~~~~~
1 error
Error: Build failed with 1 error:
node_modules/htmlparser2/lib/Parser.js:133:36: error: Could not resolve "events" (set platform to "node" when building for node)
at failureErrorWithLog (/Volumes/DUMBLEDORE1/Users/fficnar/Projects/Shared Projects/mablung-virtual-pug/node_modules/esbuild/lib/main.js:640:15)
at /Volumes/DUMBLEDORE1/Users/fficnar/Projects/Shared Projects/mablung-virtual-pug/node_modules/esbuild/lib/main.js:504:31
at handleIncomingPacket (/Volumes/DUMBLEDORE1/Users/fficnar/Projects/Shared Projects/mablung-virtual-pug/node_modules/esbuild/lib/main.js:486:9)
at Socket.readFromStdout (/Volumes/DUMBLEDORE1/Users/fficnar/Projects/Shared Projects/mablung-virtual-pug/node_modules/esbuild/lib/main.js:429:7)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:303:12)
at readableAddChunk (_stream_readable.js:279:9)
at Socket.Readable.push (_stream_readable.js:218:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:188:23) {
errors: [
{
location: [Object],
text: 'Could not resolve "events" (set platform to "node" when building for node)'
}
],
warnings: []
}
...但是如果安装了包裹...
npm install --save-dev parcel-bundler
……它成功了。
测试是...
import '@virtualpatterns/mablung-source-map-support/install'
import _Bundler from 'esbuild'
import Path from 'path'
const { 'build': Bundle } = _Bundler
const FilePath = __filePath
const Require = __require
async function main() {
try {
await Bundle({
'entryPoints': [ Require.resolve('../library/utility.js') ],
'outfile': `process/esbuild${Path.extname(FilePath)}`,
'minify': false,
'bundle': true
})
} catch (error) {
console.error(error)
}
}
main()
...但我也尝试从命令行运行以下命令,但出现相同的错误(无堆栈跟踪)...
esbuild distributable-esmodule/library/utility.js --bundle --outdir=process/esbuild --sourcemap --platform=browser --log-level=info --strict
node_modules/htmlparser2/lib/Parser.js:133:36: error: Could not resolve "events" (set platform to "node" when building for node)
require("inherits")(Parser, require("events").EventEmitter);
~~~~~~~~
1 error
冒犯require("events")
来自html-to-vdom
. 我的utility.js 很小,包含以下导入的...
import _ConvertToVirtualNode from 'html-to-vdom'
import CreateVirtualNode from 'virtual-dom/h.js'
import VirtualNode from 'virtual-dom/vnode/vnode.js'
import VirtualText from 'virtual-dom/vnode/vtext.js'
我正在使用 esbuild v0.7.19。帮助。我还应该提供什么?