#Has anyone gotten chalk to work with their discord bot split out into the index.js and then the comm
1 messages ยท Page 1 of 1 (latest)
which one
{
"name": "chalk",
"version": "5.0.0",
"description": "Terminal string styling done right",
"license": "MIT",
"repository": "chalk/chalk",
"funding": "https://github.com/chalk/chalk?sponsor=1",
"type": "module",
"exports": "./source/index.js",
"imports": {
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
"#supports-color": {
"node": "./source/vendor/supports-color/index.js",
"default": "./source/vendor/supports-color/browser.js"
}
},
"types": "./source/index.d.ts",
"engines": {
"node": "^12.17.0 || ^14.13 || >=16.0.0"
},
"scripts": {
"test": "xo && c8 ava && tsd",
"bench": "matcha benchmark.js"
},
"files": [
"source",
"!source/index.test-d.ts"
],
"keywords": [
"color",
"colour",
"colors",
"terminal",
"console",
"cli",
"string",
"ansi",
"style",
"styles",
"tty",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"log",
"logging",
"command-line",
"text"
],
"devDependencies": {
"@types/node": "^16.11.10",
"ava": "^3.15.0",
"c8": "^7.10.0",
"color-convert": "^2.0.1",
"execa": "^6.0.0",
"log-update": "^5.0.0",
"matcha": "^0.7.0",
"tsd": "^0.19.0",
"xo": "^0.47.0",
"yoctodelay": "^2.0.0"
},
"xo": {
"rules": {
"unicorn/prefer-string-slice": "off"
}
},
"c8": {
"reporter": [
"text",
"lcov"
],
"exclude": [
"source/vendor"
]
}
}
In the guide it tells about a folder commands
I guess chalk is in that folder in your case
no chalk isnt a command it's a node package that lets u put colors in your logging
yeah it says chalk.blue isnt a function
but clearly it is
so im probably importing incorrectly
Like, I wanna see if you have anything at all in that module
console.log(chalk)
So I can see if it is an importing problem
i see
Promise {
[Module: null prototype] {
Chalk: [class Chalk],
chalkStderr: [Function: chalk] createChalk { level: 3 },
default: [Function: chalk] createChalk { level: 3 },
supportsColor: { level: 3, hasBasic: true, has256: true, has16m: true },
supportsColorStderr: { level: 3, hasBasic: true, has256: true, has16m: true }
}
}
Use await import("chalk")
const chalk = await import('chalk');
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
This is expected
even when i put it in the modile.exports {} i still get the chalk.blue is not a function
I recommend you to use ES6 syntax when importing, and avoid dynamically import
is that require?
const chalk = require("chalk");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
Instead change the require of index.js in ... to a dynamic import() which is available in all CommonJS modules.
this is what it says to do when i did require
Why don't you use ES6 syntax?
I guess I don't know what ES6 syntax is for importing.
back to the outside module thing:
import chalk from 'chalk';
^^^^^^
SyntaxError: Cannot use import statement outside a module
IMPORTANT: Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now
You're using TS?
No clue tbh. I just looked at the discord.js tutorial and they made it seem real simple to install with no other considerations ๐คฃ
yep
Do you use .ts or .js
.js
In your package.json add "type": "module"
now all my other require statements break
its ok this isnt worth colors in my console 
I'll just deal with it.
I appreciate your help though
Since I can't see all your project, is not easy to tell solutions that fits the best. If you insist on using require in other files, then you should do what the IMPORTANT notice tells you. Downgrade to version 4, and then use require("chalk") (also reversing the package.json)
Yeah I'll look into chalk 4, thanks ๐
You're welcome