IDE: Replit
Good afternoon, thanks for checking out.
I wanted to implement absolute imports to my node project, but something odd is happening whenever I try to run the code.
Here are the things I set for my jsconfig.json file:
{
"compilerOptions": {
"baseUrl": "src"
}
}
Now, this is how i'm calling the file I need inside another one:
const {title} = require('util.js')
Oddly, replit's intellisense shows up the right path: Thumbs Up From Replit
But then, when I finally execute the code, I get this error message:
Error: Cannot find module '/home/runner/Moniqueta-Discordjs/node_modules/util.js/index.js'. Please verify that the package.json has a valid "main" entry at tryPackage (node:internal/modules/cjs/loader:353:19) at Function.Module._findPath (node:internal/modules/cjs/loader:566:18) at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/home/runner/Moniqueta-Discordjs/src/commands/rps.js:2:17) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) { code: 'MODULE_NOT_FOUND', path: '/home/runner/Moniqueta-Discordjs/node_modules/util.js/package.json', requestPath: 'util.js' }
I tried following the error by adding a "valid main entry to my package.json" file, like this:
{
"name": "moniqueta-discordjs",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"keywords": [],
"author": "sum117",
"license": "ISC",
"dependencies": {
"@replit/database": "^2.0.2",
"discord.js": "^13.8.0",
"src": "^1.1.2",
"util.js": "^0.0.0"
}
}
And when I checked it, it had "util.js" as a declared dependency, I really don't understand what's going on.
Thanks for reading. What am I missing? I really would love this to work...
If my explanation is not enough, you can access my open source code via the link.