0

I'm currently trying to use path.join to join a directory. After it's compiled, it throws an error (surprised typescript didn't pick up on it while compiling)

/media/chen/storage/development/urlshortener/src/database/database.js:9
        filename: path_1["default"].join(__dirname, 'chen.db')
                                    ^
TypeError: Cannot read property 'join' of undefined
    at Object.<anonymous> (/media/chen/storage/development/urlshortener/src/database/database.js:9:37)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/media/chen/storage/development/urlshortener/src/index.ts:52:1)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Module.m._compile (/media/chen/storage/development/urlshortener/node_modules/ts-node/src/index.ts:1056:23)

Here is database.ts

import knex from 'knex';
import path from 'path';

export const db = knex({
  client: 'sqlite3',
  connection: {
    filename: path.join(__dirname, 'chen.db')
  },
  useNullAsDefault: true
});

And here is the compiled database.js

"use strict";
exports.__esModule = true;
exports.db = void 0;
var knex_1 = require("knex");
var path_1 = require("path");
exports.db = knex_1["default"]({
    client: 'sqlite3',
    connection: {
        filename: path_1["default"].join(__dirname, 'chen.db')
    },
    useNullAsDefault: true
});

In VSCode, there are no errors showing at all, and type definitions work as normal
This is my typescript config https://hastebin.com/okikowabip.json
This is my package.json https://hastebin.com/inuzidobom.json

Chen
  • 107
  • 1
  • 12
  • Is TypeScript the only thing involved in compiling the code? No webpack or babel?. What version of TypeScript? Please provide your TypeScript config as text, not as a link to another site where there might be some text. – Heretic Monkey Jan 09 '21 at 21:13
  • @HereticMonkey Typescript is the only thing involved yes. I'm not using webpack because it's not necessary, since this is for a backend. And I use hastebin because it seems really stupid to include large pieces of text directly in a question, so I instead link it. It keeps it more organized. And hastebin is reliable so theres no chance that whatever I link to on hastebin will be gone. – Chen Jan 09 '21 at 21:30

0 Answers0