Closed 2coo closed 9 months ago
I get the same issue. In my case it happen when i try to import dayjs
relavant tsconfig.json
"outDir": "./build",
"paths": {
"@app/db": ["../db"],
"@app/db/*": ["../db/*"],
"@app/redis": ["../redis"],
"@app/redis/*": ["../redis/*"],
"@app/emitter": ["../emitter"],
"@app/emitter/*": ["../emitter/*"],
"@app/dayjs": ["../dayjs"],
"@app/dayjs/*": ["../dayjs/*"],
"@app/utils": ["../utils"],
"@app/utils/*": ["../utils"],
"@app/values": ["../values"],
"@app/values/*": ["../values/*"]
},
tsc input:
import dayjs from "dayjs";
tsc output/tsc-alias input:
const dayjs_1 = __importDefault(require("dayjs"));
tsc-alias output:
const dayjs_1 = __importDefault(require("../dayjs"));
whats strange is there are other dayjs imports that weren't touched
const dayjs_1 = __importDefault(require("../dayjs"));
const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
const arraySupport_1 = __importDefault(require("dayjs/plugin/arraySupport"));
const isLeapYear_1 = __importDefault(require("dayjs/plugin/isLeapYear"));
its really unfortunate because this is the closest i got to having my project transpiled and running with just node. literally if i just remove the ../
from this line manually it works. The other alternative have even more issues. typescript-transform-paths
doesn't correctly replace relative paths for me.
this package correctly replaces
require("@app/redis")
with
require("../redis")
it treated outDir
as the new base/root which is what i actually want
typescript-transform-paths
does this (still tries to pull original ts file from outside outDir
):
require("../../../redis");
This solved it for me: https://github.com/justkey007/tsc-alias/issues/185, but i'm using ES imports not CommonJS
Before compiling
After compiling
To produce
graphql
is external dependency I installed from npm registry and I have~/graphql
path alias which points to./src/graphql
so that I think it collides with~/graphql
tsconfig.json