I am trying to run colorthief, and I downloaded it from the github repo directly(as npm install -g colorthief or npm istall --save colorthief) did not work. I have colorthief in node_modules, and test.js in colorthief. However, I get the following error message. Any advice?
test.js
//text logging init @ output.txt
const fs = require('fs');
const myConsole = new console.Console(fs.createWriteStream('./output.txt'));
//init colorthief
const { resolve } = require('path');
const ColorThief = require('colorthief');
//load image
const img = resolve(process.cwd(), 'cropped_image.jpg');
//getting color
ColorThief.getColor(img)
.then((color) => {
myConsole.log(color);
})
error msg
d4@d4-desktop:~/myflection/node_modules/colorthief$ node test.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'colorthief'
Require stack:
- /home/d4/myflection/node_modules/colorthief/test.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/d4/myflection/node_modules/colorthief/test.js:7:20)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/d4/myflection/node_modules/colorthief/test.js' ]
}
Node.js v17.9.0
I'm not sure what you are trying to do but I don't think you want to run anything from within the
node_modulesfolder.Move test.js to
myflectionand run it from there.