esbuild 上的纱线构建失败
Posted
技术标签:
【中文标题】esbuild 上的纱线构建失败【英文标题】:Yarn Build Fails on the esbiuild 【发布时间】:2021-11-06 20:21:41 【问题描述】:我正在进行的项目使用 Yarn,我是新手,但遇到了一些初期问题。项目运行但js没有。
我在全球范围内安装了 Node.js (v16.9.0) 和 Yarn。
我提取了 repo 并从命令中导航到项目路径并执行了yarn install
;
运行良好。
这是我可以使用的纱线命令列表
➤ YN0000: build:css 'yarn postcss assets/css/site.css -o wwwroot/css/site.css'
➤ YN0000: build:js 'node build.js'
➤ YN0000: build 'yarn run-p build:css build:js'
➤ YN0000: publish:css 'yarn cross-env NODE_ENV=production yarn postcss assets/css/site.css -o wwwroot/css/site.css'
➤ YN0000: publish:js 'yarn cross-env NODE_ENV=production node build.js'
➤ YN0000: publish 'yarn cross-env NODE_ENV=production yarn run-p publish:css publish:js'
➤ YN0000: stackup '../../scripts/dev/start_mssql_container.sh && dotnet watch run'
➤ YN0000: watch 'yarn npm-watch'
➤ YN0000: Done in 0s 3ms
当我尝试执行yarn build
时,它给了我以下信息。是不是节点设置有问题?还是纱线问题?
我已尝试搜索此问题,但到目前为止我的最佳猜测是 esbuild 不正确,但不确定如何修复。
> .yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
32 │ let resolveDir = args.path.match(/(.+\/)/)[1];
╵ ^
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:31:12: note: This error came from the "onLoad" callback registered here
31 │ build.onLoad( filter: /.*/, namespace: "pnp" , async args =>
╵ ~~~~~~
at setup (C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:31:13)
at handlePlugins (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:659:7)
> .yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
32 │ let resolveDir = args.path.match(/(.+\/)/)[1];
╵ ^
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:31:12: note: This error came from the "onLoad" callback registered here
31 │ build.onLoad( filter: /.*/, namespace: "pnp" , async args =>
╵ ~~~~~~
at setup (C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:31:13)
at handlePlugins (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:659:7)
> .yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
32 │ let resolveDir = args.path.match(/(.+\/)/)[1];
╵ ^
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:31:12: note: This error came from the "onLoad" callback registered here
31 │ build.onLoad( filter: /.*/, namespace: "pnp" , async args =>
╵ ~~~~~~
at setup (C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:31:13)
at handlePlugins (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:659:7)
> .yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
32 │ let resolveDir = args.path.match(/(.+\/)/)[1];
╵ ^
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:31:12: note: This error came from the "onLoad" callback registered here
31 │ build.onLoad( filter: /.*/, namespace: "pnp" , async args =>
╵ ~~~~~~
at setup (C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:31:13)
at handlePlugins (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:659:7)
> .yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
32 │ let resolveDir = args.path.match(/(.+\/)/)[1];
╵ ^
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:31:12: note: This error came from the "onLoad" callback registered here
31 │ build.onLoad( filter: /.*/, namespace: "pnp" , async args =>
╵ ~~~~~~
at setup (C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:31:13)
at handlePlugins (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:659:7)
5 errors
Error: Build failed with 5 errors:
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
.yarn/$$virtual/esbuild-plugin-pnp-virtual-b0ebe0e05a/0/cache/esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip/node_modules/esbuild-plugin-pnp/index.js:32:50: error: [pnp-plugin] Cannot read properties of null (reading '1')
at failureErrorWithLog (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:1160:15)
at buildResponseToResult (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:896:32)
at C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:991:20
at C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:542:9
at handleIncomingPacket (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:631:9)
at Socket.readFromStdout (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
errors: [
detail: TypeError: Cannot read properties of null (reading '1')
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
at handleRequest (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:577:36)
at handleIncomingPacket (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:624:7)
at Socket.readFromStdout (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:199:23),
location: [Object],
notes: [Array],
text: "[pnp-plugin] Cannot read properties of null (reading '1')"
,
detail: TypeError: Cannot read properties of null (reading '1')
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
at handleRequest (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:577:36)
at handleIncomingPacket (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:624:7)
at Socket.readFromStdout (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:199:23),
location: [Object],
notes: [Array],
text: "[pnp-plugin] Cannot read properties of null (reading '1')"
,
detail: TypeError: Cannot read properties of null (reading '1')
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
at handleRequest (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:577:36)
at handleIncomingPacket (C:\Development\Project\src\Fixie.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:624:7)
at Socket.readFromStdout (C:\Development\Fixie\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:199:23),
location: [Object],
notes: [Array],
text: "[pnp-plugin] Cannot read properties of null (reading '1')"
,
detail: TypeError: Cannot read properties of null (reading '1')
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
at handleRequest (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:577:36)
at handleIncomingPacket (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:624:7)
at Socket.readFromStdout (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:199:23),
location: [Object],
notes: [Array],
text: "[pnp-plugin] Cannot read properties of null (reading '1')"
,
detail: TypeError: Cannot read properties of null (reading '1')
at C:\Development\Project\src\Project.Web\.yarn\$$virtual\esbuild-plugin-pnp-virtual-b0ebe0e05a\0\cache\esbuild-plugin-pnp-npm-0.3.0-c8f5fdc52d-b80ab17bea.zip\node_modules\esbuild-plugin-pnp\index.js:32:51
at callback (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:744:34)
at handleRequest (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:577:36)
at handleIncomingPacket (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:624:7)
at Socket.readFromStdout (C:\Development\Project\src\Project.Web\.yarn\unplugged\esbuild-npm-0.8.57-7fe43e451a\node_modules\esbuild\lib\main.js:509:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:199:23),
location: [Object],
notes: [Array],
text: "[pnp-plugin] Cannot read properties of null (reading '1')"
],
warnings: []
【问题讨论】:
【参考方案1】:更新我现在已经解决了这个问题。
yarn install 后执行以下命令,
纱线添加@yarnpkg/esbuild-plugin-pnp
然后在 build.js 中将第 2 行替换为
const pnpPlugin = require('esbuild-plugin-pnp');
然后做 yarn add esbuild -D
然后纱线构建应该可以工作。
【讨论】:
以上是关于esbuild 上的纱线构建失败的主要内容,如果未能解决你的问题,请参考以下文章
在 ReactJS 中构建纱线,分配失败 - JavaScript 堆内存不足
Next.js 纱线构建因 plotly.js 失败(发生构建错误 ReferenceError: self is not defined)