Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong file returned - ATENTION #13

Open
Deathrage opened this issue Mar 5, 2019 · 3 comments
Open

Wrong file returned - ATENTION #13

Deathrage opened this issue Mar 5, 2019 · 3 comments

Comments

@Deathrage
Copy link

`// root/index.js
module.exports = function() { return getCallerFile(); }

// root/dir/app.js
const func = require('../index.js');
func(); // returns root/index.js`

Firstly encourntered this when using TS-NODE. It occurs in node too. Caller file is app.js yet definition file index.js is returned.

@stefanpenner
Copy link
Owner

@Deathrage interesting, that seem strange as getCallerFiles tests do test these common scenarios, and they seem to work fine.

Could you provide a reproduction, I can gladly debug it then.

@Deathrage
Copy link
Author

It seems like Typescript related issue. I am testing with typescript default settings through TSNODE.

Typescript:

// ts/folder/index.ts

import testFunc from '../func';
testFunc().then(console.log);

// ts/func.ts
const getCallerFile = require('get-caller-file');

export default async function () {
    let caller = getCallerFile();
    return caller;
}

This logs /func.ts. (incorrect)

Javascript (not result of TSC, I wrote vanila counterpart as test):

// vanila/folder/index.js
var func = require('../func.js');

func ().then(console.log);

// vanila/func.js
const getCallerFile = require('get-caller-file');

module.exports = async function () {
    let caller = getCallerFile();
    return caller;
}

This logs /index.js. (correct)

Firstly I suspected it might be related to TS-NODE as I use it during development but after transpiling to JS and executing JS directly the issue persists. TSC does not do any kind of bundling, it just spawns transpiled file next to ts file. It might be realted to the way how TSC handles transpilation of ES6 to CommonJS. Code written in vanila JS works well.

Version of TSC: 3.3.3
Version of Node: 10.9.0

@Deathrage
Copy link
Author

@stefanpenner

@Deathrage Deathrage changed the title Wrong file returned Wrong file returned - ATENTION Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants