#cant import realtive files

8 messages · Page 1 of 1 (latest)

hollow grotto
#

Cant import realtive functions in the same folder.

Error:

    throw new ERR_MODULE_NOT_FOUND(
          ^
CustomError: Cannot find module '/Users/.../bot/src/events/db' imported from /Users/.../bot/src/events/createEvent.ts```

db.ts

`export const db = new KyselyAuth<Database>({})`

createEvent.ts

`import { db } from './db'`

TSConfig: 
(changed it a lot in hopes itd work)

```json
{
  "compilerOptions": {
    "module": "ESNext",
    "outDir": "build",
    "rootDir": "src",
    "strict": true,
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true,
    
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,

    "allowJs": true,
    "checkJs": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
  },
  "include": ["src"],
  "exclude": ["build", "node_modules"]
}```
gray rose
#

this is at runtime, changing your tsconfig won't change much

#

you probably need a file extension

#

considering the .ts in the error, looks like you're running with ts-node/tsx, in which case use .ts

hollow grotto
#

Yea im running with ts-node-esm src/main.ts

#

i assume theres prob a better thing to use

gray rose
#

yeah you'll need .ts extensions iirc

hollow grotto
#

"An import path cannot end with a '.ts' extension. Consider importing './db.js' instead."

"Cannot find module './db.js' or its corresponding type declarations." ;-;