Libraries and communications:
- typescript v5.4.5
- node v20.11.1
- pnpm v9.1.0
- ts-node v10.9.2
- nodemon v3.1.3
On Stack Overflow, I found a similar problem and solved it, but there is another problem where I can’t solve it or find it, I used a node project to run discord.js bot, but because of my imports I couldn’t run the code, the script used is “dev”, my package.json
:
"scripts": {
"dev": "nodemon --exec node --experimental-loader ts-node/esm src/middleware.ts",
"knip": { "knip": "knip",
"knip:fix": "knip --fix",
"lint": "eslint . --ext .ts"
},
code:
import { client, Next } from '@/app';
import { CheckBasicDiscordGuild, SubBuffer } from '@/components';
// Handle unhandled promise rejections and uncaught exceptions
process.on('unhandledRejection', SubBuffer);
process.on('uncaughtException', SubBuffer);
const BooleanParam = await CheckBasicDiscordGuild(client);
if (BooleanParam === true) Next(client);
tsconfig.json & tsconfig.paths.json:
{
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"declaration": false,
"declarationMap": false,
"importHelpers": true,
"newLine": "crlf",
"noEmitHelpers": true,
"outDir": "build",
"preserveConstEnums": true,
"removeComments": false,
"sourceMap": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"ESNext"
],
"target": "ESNext",
"useDefineForClassFields": true,
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"build"
],
"extends": "./tsconfig.paths.json"
}
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@base/*": ["./*"],
// "@components/*": ["./src/components/*"],
// "@app/*": ["./src/app/*"],
// "@constants/*": ["./src/constants/*"],
// "@database/*": ["./src/database/*"],
// "@handlers/*": ["./src/handlers/*"],
"@/*": ["./src/*"]
}
}
}
error:
> nodemon --exec node --experimental-loader ts-node/esm src/middleware.ts
[nodemon] 3.1.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `node --experimental-loader ts-node/esm src/middleware.ts`
(node:15548) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./")));'
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^
Error: Cannot find package '@/app' imported from C:UsershardbDocumentsgitlab-projectsassisterr-appsrcmiddleware.ts
at packageResolve (C:UsershardbbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodedist-rawnode-internal-modules-esm-resolve.js:757:9)
at moduleResolve (C:UsershardbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodedist-rawnode-internal-modules-esm-resolve.js:798:18)
at Object.defaultResolve (C:UsershardbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodedist-rawnode-internal-modules-esm-resolve.js:912:11)
at C:UsershardbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodesrcesm.ts:218:35
at entrypointFallback (C:UsershardbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodesrcesm.ts:168:34)
at C:UsershardbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodesrcesm.ts:217:14
at addShortCircuitFlag (C:UsershardbDDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodesrcesm.ts:409:21)
at resolve (C:UsershardbbDocumentsgitlab-projectsassisterr-appnode_modules.pnpm[email protected]_@[email protected][email protected]node_modulests-nodesrcesm.ts:197:12)
at nextResolve (node:internal/modules/esm/hooks:865:28)
at Hooks.resolve (node:internal/modules/esm/hooks:303:30)
Node.js v20.11.1
[nodemon] app crashed - waiting for file changes before starting...
New contributor
Nazar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.