Skip to content

Problem sharing TS code files between different Visual Studio projects #7153

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

Closed
KoenT-X opened this issue Feb 19, 2016 · 7 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified

Comments

@KoenT-X
Copy link

KoenT-X commented Feb 19, 2016

I've been trying to make 2 Visual Studio 2015 CE web app projects share the same TypeScript file, but could not find a way to do this. I am using the AMD module system with require.

While coding VS seems to be fine with the require("......") statement for the common code file. However, when running, I get an exception from require.

I have more details on the general problem in this SO post:
http://stackoverflow.com/questions/35506086/using-typescript-files-in-different-web-apps-with-require-amd

and the repository with a self-contained example that reproduces the problem can be found here:
https://bitbucket.org/KoenT_IM/typescripttests

Just build and run the project under Applications/CodeSharingApp1 to reproduce this.

Perhaps the fact that the relative path "climbs out" of the project path to reference the common TS file, is what causes the problem. But then I'm not sure how to share a folder with common TS code files between different projects...

@mhegazy
Copy link
Contributor

mhegazy commented Feb 19, 2016

what version of TS are you using?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Feb 19, 2016
@mhegazy mhegazy self-assigned this Feb 20, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 20, 2016
@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 20, 2016
@KoenT-X
Copy link
Author

KoenT-X commented Feb 22, 2016

I'm using TypeScript 1.7.6 (in VS2015 CE).

@heroboy
Copy link

heroboy commented May 10, 2016

hi, I have the same problem. Both vscode and vs2015 can't handle shared files in multipy projects.
For example, I have files:

/a/a.ts                ->    import {x} from "../shared/x"
/a/tsconfig.json
/b/b.ts                ->    import {x} from "../shared/x"
/b/tsconfig.json
/x/x.ts                ->    export var x = 1;

The "Find All Reference" doesn't find 'x' in both a.ts and b.ts

@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2016

The "Find All Reference" doesn't find 'x' in both a.ts and b.ts

@heroboy, looks like this is a diffrent issue. this is fixed in #7353

@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2016

@KoenT-IM consider specifing a require configuration (http://requirejs.org/docs/api.html#config) to map the location of your shared module.

the other option, is to drop all your modules into a single output location, and use baseURL (a TS 2.0 feature, available now in typescript@next).

so your sources would look like:

projectA\
    a.ts     => `import foo from "b"`
projectB\
    b.ts   

with tsconfig.json as:

{
    "compilerOptions": {
        "baseURL" : "./out",
        "outDir": "./out"
    }
}

see https://github.com/Microsoft/TypeScript-Handbook/blob/release-2.0/pages/Module%20Resolution.md#base-url for more details.

@mhegazy mhegazy closed this as completed Jun 6, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jun 6, 2016

the original issue seems to be addressed. please reopen if this is not the case.

@KoenT-X
Copy link
Author

KoenT-X commented Jun 7, 2016

Thanks mhegazy. Will verify and come back to this if needed soon (working towards a release now).

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants