简体   繁体   English

我已经使用 npm 全局安装了夏普,但我不能使用它

[英]I have installed Sharp globally using npm but I can't use it

Whenever I use sharp --version, it shows sharp command not found每当我使用sharp --version时,它都会显示未找到锐利的命令

sharp --version
bash: sharp: command not found

I can't use我无法使用

const sharp= require('sharp');

It gives error of - "Module not found"它给出了错误-“找不到模块”

If I use it without requiring it, I get error like- "sharp is not defined"如果我在不需要它的情况下使用它,我会收到类似“未定义尖锐”的错误

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 file, 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文件,

here an exapmle of using sharp to get information of an image这里是使用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();

run the app运行应用程序

node app.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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