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

Ts-node fails when using symlinks #396

Closed
mtfranchetto opened this issue Jul 21, 2017 · 10 comments
Closed

Ts-node fails when using symlinks #396

mtfranchetto opened this issue Jul 21, 2017 · 10 comments
Labels
bug you can do this Good candidate for a pull request.

Comments

@mtfranchetto
Copy link

Hi,

I'm reporting here an issue I described here #391 (comment).
To reproduce the problem you can just use the frameworks we are developing.

git clone -b housekeeping [email protected]:tierratelematics/prettygoat.git
git clone -b 4.0.0-alignment [email protected]:tierratelematics/prettygoat-cassandra-store.git

You can download the sources from there and install deps on both projects. Then go to prettygoat-cassandra-store and npm link prettygoat. You can see that both tsc and ts-node are failing. Link also rxjs (the one in the prettygoat's node_modules) to the cassandra module and tsc now it's working.

The commands I'm using to test tsc/ts-node:
tsc --outDir build
ts-node scripts/prettygoat-cassandra-store.ts

@blakeembrey blakeembrey added bug you can do this Good candidate for a pull request. labels Jul 24, 2017
@tlaziuk
Copy link

tlaziuk commented Aug 4, 2017

I've similar issue when using a bin file, it may be related.

The bin file:

#!/usr/bin/env node
"use strict";
const config = require("../tsconfig.json");
require("ts-node").register(config);
require("../cli/index");

So this is a bin file, a symlink to that file is created in /usr/bin/BIN which is pointing to a real path, eg. /home/tlaziuk/project/bin/index.js.

../cli/index is a TS file which compiles without any problems when using the tsc.

When executing the bin inside the project root everything works fine, but when I want to execute that anywhere else it looks like there are no @types installed - errors like Cannot find module 'path'. are thrown during the TS compile.

> ts-node "--version"

ts-node v3.3.0
node v8.2.1
typescript v2.4.2

@k8w
Copy link

k8w commented Nov 20, 2017

Same problem.

Problem
File structure:

|- __shared
    |- ShareClass.ts
|- backend
    |- <shared>  // symlink to ../__shared
    |- index.ts

__shared/ShareClass.ts

import XXX from 'some-node-modules';
...

backend/index.ts

import XXX from './shared/ShareClass';
ts-node index.ts

It will throw error:

TSError: ⨯ Unable to compile TypeScript
..__shared\ShareObj.ts (1,26): Cannot find module 'tsrpc-protocol'. (2307)

Expect
shared/ShareObj.ts is treated as its symlink path.

Demo
A demo project here

cd backend
npm install
ts-node index.ts

@k8w
Copy link

k8w commented Nov 20, 2017

Hi guys, I just find a solution to resolve this.
Just use:

ts-node --preserve-symlinks index.ts

@blakeembrey The problem is mainly because in TypeScript preserveSymlinks is true by default, while it is false in NodeJS by default.

@k8w
Copy link

k8w commented Nov 20, 2017

@blakeembrey Maybe it's better to auto set --preserve-symlinks if it is not false in tsconfig.json ?

@kirillgroshkov
Copy link

--preserve-symlinks doesn't work:( Also, it's not documented anywhere. Is it still supported? Any workarounds?

@blakeembrey
Copy link
Member

node -r ts-node/register --preserve-symlinks script.ts

@j-oliveras
Copy link

@kirillgroshkov I know is late, but setting environment var NODE_PRESERVE_SYMLINKS to 1 should work (only node 7.1 or newer).

@mauril26
Copy link

mauril26 commented Sep 6, 2019

mocha -r ts-node/register --preserve-symlinks ./src/**/*.test.ts

this worked for me.

I have the code (./src) in a place and a workspace in other location (which contains node_modules), ie:

  • {real_place}
    | -src

///////////////////////

  • workspace
    | - node_modules/
    | - src/ --> {real_place}/src

running the script with --preserve-symlinks fix the missing module error. (chai in my case)

@cspotcode
Copy link
Collaborator

Symlink issues are likely fixed in 9.0.0 by #970

@holylander
Copy link

--preserve-symlinks

this setting did the job while using ts-node-dev. Thanks a lot @k8w

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug you can do this Good candidate for a pull request.
Projects
None yet
Development

No branches or pull requests

10 participants