@@ -9,6 +9,9 @@ declare const ESBUILD_VERSION: string;
9
9
// external code relies on this.
10
10
export var ESBUILD_BINARY_PATH : string | undefined = process . env . ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH ;
11
11
12
+ const packageDarwin_arm64 = 'esbuild-darwin-arm64'
13
+ const packageDarwin_x64 = 'esbuild-darwin-64'
14
+
12
15
export const knownWindowsPackages : Record < string , string > = {
13
16
'win32 arm64 LE' : 'esbuild-windows-arm64' ,
14
17
'win32 ia32 LE' : 'esbuild-windows-32' ,
@@ -132,11 +135,7 @@ export function generateBinPath(): { binPath: string, isWASM: boolean } {
132
135
// helpful in that case.
133
136
const otherPkg = pkgForSomeOtherPlatform ( ) ;
134
137
if ( otherPkg ) {
135
- throw new Error ( `
136
- You installed esbuild on another platform than the one you're currently using.
137
- This won't work because esbuild is written with native code and needs to
138
- install a platform-specific binary executable.
139
-
138
+ let suggestions = `
140
139
Specifically the "${ otherPkg } " package is present but this platform
141
140
needs the "${ pkg } " package instead. People often get into this
142
141
situation by installing esbuild on Windows or macOS and copying "node_modules"
@@ -146,14 +145,46 @@ Windows and WSL environments.
146
145
If you are installing with npm, you can try not copying the "node_modules"
147
146
directory when you copy the files over, and running "npm ci" or "npm install"
148
147
on the destination platform after the copy. Or you could consider using yarn
149
- instead which has built-in support for installing a package on multiple
148
+ instead of npm which has built-in support for installing a package on multiple
150
149
platforms simultaneously.
151
150
152
151
If you are installing with yarn, you can try listing both this platform and the
153
152
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
154
153
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
155
154
Keep in mind that this means multiple copies of esbuild will be present.
155
+ `
156
+
157
+ // Use a custom message for macOS-specific architecture issues
158
+ if (
159
+ ( pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 ) ||
160
+ ( pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64 )
161
+ ) {
162
+ suggestions = `
163
+ Specifically the "${ otherPkg } " package is present but this platform
164
+ needs the "${ pkg } " package instead. People often get into this
165
+ situation by installing esbuild with npm running inside of Rosetta 2 and then
166
+ trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
167
+ 2 is Apple's on-the-fly x86_64-to-arm64 translation service).
168
+
169
+ If you are installing with npm, you can try ensuring that both npm and node are
170
+ not running under Rosetta 2 and then reinstalling esbuild. This likely involves
171
+ changing how you installed npm and/or node. For example, installing node with
172
+ the universal installer here should work: https://nodejs.org/en/download/. Or
173
+ you could consider using yarn instead of npm which has built-in support for
174
+ installing a package on multiple platforms simultaneously.
175
+
176
+ If you are installing with yarn, you can try listing both "arm64" and "x64"
177
+ in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
178
+ https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
179
+ Keep in mind that this means multiple copies of esbuild will be present.
180
+ `
181
+ }
156
182
183
+ throw new Error ( `
184
+ You installed esbuild for another platform than the one you're currently using.
185
+ This won't work because esbuild is written with native code and needs to
186
+ install a platform-specific binary executable.
187
+ ${ suggestions }
157
188
Another alternative is to use the "esbuild-wasm" package instead, which works
158
189
the same way on all platforms. But it comes with a heavy performance cost and
159
190
can sometimes be 10x slower than the "esbuild" package, so you may also not
@@ -171,8 +202,9 @@ want to do that.
171
202
throw new Error ( `The package "${ pkg } " could not be found, and is needed by esbuild.
172
203
173
204
If you are installing esbuild with npm, make sure that you don't specify the
174
- "--no-optional" flag. The "optionalDependencies" package.json feature is used
175
- by esbuild to install the correct binary executable for your current platform.` ) ;
205
+ "--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
206
+ of "package.json" is used by esbuild to install the correct binary executable
207
+ for your current platform.` ) ;
176
208
}
177
209
throw e ;
178
210
}
0 commit comments