简体   繁体   中英

"node-pre-gyp: not found" when compiling canvas with Yarn 1

I changed the path to my Next.js application on my VPS server, and now my dependencies aren't installing correctly with Yarn. (I'm on Yarn 1, not Yarn 2.)

Yarn crashes trying to build the native code for the npm module canvas , saying: node-pre-gyp: not found .

Why is this happening?

It turns out, the new path to the application had a colon : in one of the folder names. (The folder was named with an ISO timestamp, like 2021-11-03T02:02:44 , to represent when this version of the app was built.)

Colons are a special character for looking up executables in most systems: the PATH variable is usually split by colons.

I suspect that Yarn 1 has a bug where it inserts the folder name into the PATH without escaping any colons, which causes PATH to parse incorrectly. This causes the system to look in two incorrect folder names, instead of the one correct folder name, for the executables like node-pre-gyp that it needs to build special native-code dependencies like canvas .

To fix this, stop using colons in your folder names that contain Node applications where you depend on Yarn 1 for compiling native code. Rename the folder to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM