#Error: Cannot find module

5 messages · Page 1 of 1 (latest)

merry kernel
#

I have a src directory for source files and I've set the baseUrl option in my tsconfig.json to . (base directory). When I import files within src into other files within src (as shown in the example below)
src/commands/information/Ping.command.ts

import type { AstraniumClient } from "src/lib/Client";
import { Command } from "src/lib/Command";

and run the compiled JS code (using CJS), I get an error:

Error: Cannot find module 'src/lib/Command'
steel stratus
#

!*:paths-are-not-magic

vale elbowBOT
#
T6#2591
`!t6:paths-are-not-magic`:

The paths and baseUrl compiler options don't cause any remapping of imports paths, they only inform TS of existing mappings, which you'll have to setup with some other tool.

baseUrl is a pretty well-supported option (e.g. using the NODE_PATH environment variable with node or resolve.modules with webpack).
paths can be trickier to setup, (especially with node see this for node), and you may find it to not be worth the effort.

sick cliff
#

!close

vale elbowBOT
#

@merry kernel
Because your issue seemed to be resolved, this post was marked as resolved by @sick cliff.
If your issue is not resolved, you can reopen this post by running !reopen.
If you have a different question, make a new post in #1057653400046674112.