Skip to content

[Bug] Problem with running via ts-node when entry file is in a different directory #181

@Gikkman

Description

@Gikkman

If I try to run a project using ts-node, and the entry file the ts-node command points to is in a different directory from your current working directory, then the path remapping won't be correct. If you build the project however, then the path mapping will be correct. It might be that I configure something wrong along the way, but I can't really figure out what that would be in that case.

I've set up an example project you can clone that shows the issue: https://github.com/Gikkman/typescript-transform-paths-reproduce-ts-node-problem

Clone the project, then run npm i to set everything up. Running npm run dev:a will try to run ts-node in a way that crashes, but running npm run dev:b will run it in a way so it works. You can then build the project, using npm run build. If you inspect the output (under the build folder), you'll see that the build output has correct mappings. Running the built projects via npm run start:a or npm run start:b will also show that both works post-build.

If I were to theorize, I'm guessing the first file's path resolution doesn't take into consideration that it might not be in the same directory as script is invoked from. It isn't hard to work around IMO (just make a bootstrap script in the same directory as the package.json) but I thought it might be worth mentioning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions