[英]I have installed Sharp globally using npm but I can't use it
每当我使用sharp --version时,它都会显示未找到锐利的命令
sharp --version
bash: sharp: command not found
我无法使用
const sharp= require('sharp');
它给出了错误-“找不到模块”
如果我在不需要它的情况下使用它,我会收到类似“未定义尖锐”的错误
you need to install it locally npm install sharp
to be able to require it, to be able to install an npm package for a node.js project you need to have package.json file inside that project folder, use npm init
to create that package.json文件,
这里是使用Sharp获取图像信息的示例
//app.js
const sharp = require("sharp");
async function getMetadata() {
try {
const metadata = await sharp("image.png").metadata();
console.log(metadata);
} catch (error) {
console.log(`An error occurred during processing: ${error}`);
}
}
getMetadata();
运行应用程序
node app.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.