我正试图将一个VS代码扩展项目与Bun捆绑在一起,当我这样做时,我会得到这些错误。我猜它在从path
导入时遇到了麻烦,我猜这是一个Node特定的模块。我该怎么办?
mrakgr@Lain:/mnt/c/Users/Marko/Source/Repos/The Spiral Language/VS Code Plugin$ bun build ./src/index.ts --outdir ./out --external vscode
./index.js 107.19 KB
warn: Import "extname" will always be undefined because there is no matching export in "node:path"
switch (path.extname(doc.uri.path)) {
^
/mnt/c/Users/Marko/Source/Repos/The Spiral Language/VS Code Plugin/src/index.ts:159:22 8076
warn: Import "basename" will always be undefined because there is no matching export in "node:path"
if (path.basename(doc.uri.path,".spiproj") === "package") {spiprojOpen(doc)}
^
/mnt/c/Users/Marko/Source/Repos/The Spiral Language/VS Code Plugin/src/index.ts:161:26 8156
warn: Import "join" will always be undefined because there is no matching export in "node:path"
const compiler_path = path.join(__dirname,"../compiler/Spiral.dll")
^
/mnt/c/Users/Marko/Source/Repos/The Spiral Language/VS Code Plugin/src/index.ts:261:36 13623
[180ms] bundle 27 modules
2条答案
按热度按时间iqih9akk1#
如在docs上所写的,bun具有与node的兼容性,在section node:path上完全实现了兼容性。如果没有代码片段,就很难更进一步,顺便说一下,我会检查导入
const path = require('node:path');
,或者我会在GitHub上打开一个问题,详细说明重现这种情况的步骤。wbgh16ku2#
使用
bun build example.ts --outdir ./out --target <bun/node>
确保目标是bun运行时(或节点运行时其中<bun/node>是bun或node。
bun build
的默认行为是以浏览器为目标。浏览器是一个安全的地方,没有明确的权限访问用户的文件系统是不允许的。像fs
和path
这样的库不能正常工作,因此bun抱怨在为浏览器构建时包含它们。以运行时(bun/node)为目标会告诉bun build
您的代码将在本地/服务器端运行,并允许访问文件系统。