Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

typescript - Path module - Cannot read property of "join" undefined

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...