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
question from:
https://stackoverflow.com/questions/65647598/path-module-cannot-read-property-of-join-undefined 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…