该问题已经解决
注意:我的版本是"version": "0.14.39", 必须要这个版本才行
node_modules目录下的 esbuild 目录下的lib目录下必须要有 downloaded-esbuild-darwin-64-esbuild 这个文件
我已经放在附件里,只要加入该文件就可以了,这个也是我运气好,第一次创建项目时,通过npm install 下载到这个文件,后来我发现官方esbuild更新过后,就再也无法下载到了。
查看esbuild/lib/main.js
下面有如下这句:(1768行 - 1841行)
unction downloadedBinPath(pkg, subpath) {
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
}
function generateBinPath() {
if (ESBUILD_BINARY_PATH) {
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
}
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
let binPath;
try {
binPath = require.resolve(`${pkg}/${subpath}`);
} catch (e) {
binPath = downloadedBinPath(pkg, subpath);
if (!fs.existsSync(binPath)) {
try {
require.resolve(pkg);
} catch {
const otherPkg = pkgForSomeOtherPlatform();
if (otherPkg) {
throw new Error(`
You installed esbuild on another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "${otherPkg}" package is present but this platform
needs the "${pkg}" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.
If you are installing with npm, you can try not copying the "node_modules"
directory when you copy the files over, and running "npm ci" or "npm install"
on the destination platform after the copy. Or you could consider using yarn
instead which has built-in support for installing a package on multiple
platforms simultaneously.
If you are installing with yarn, you can try listing both this platform and the
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.
Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.
`);
}
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
If you are installing esbuild with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by esbuild to install the correct binary executable for your current platform.`);
}
throw e;
}
}
let isYarnPnP = false;
try {
require("pnpapi");
isYarnPnP = true;
} catch (e) {
}
if (isYarnPnP) {
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`);
if (!fs.existsSync(binTargetPath)) {
fs.copyFileSync(binPath, binTargetPath);
fs.chmodSync(binTargetPath, 493);
}
return { binPath: binTargetPath, isWASM };
}
return { binPath, isWASM };
}
traveller2022
确实可以
2022-06-23 17:26
traveller2022
就是版本号得更新下
2022-06-23 17:26
1***@qq.com
回复 traveller2022: 请问怎么更新版本号?谢先了!
2022-07-29 19:42
traveller2022
回复 1***@qq.com: 把那个curl的地址里的esbuild版本号换成自己项目实际的版本号,再curl
2022-08-20 16:27
1***@qq.com
可以,谢谢大佬
2022-11-11 20:14
在在
运行之后还是报错呐
2023-05-19 19:11