簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM