Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Installing React via documented method doesn't work #782

Closed
xmcclure opened this issue Mar 14, 2017 · 11 comments
Closed

Installing React via documented method doesn't work #782

xmcclure opened this issue Mar 14, 2017 · 11 comments

Comments

@xmcclure
Copy link

I have a web application which uses particular versions of React and JQuery. It previously installed these by installing the jquery and react-global packages via tsd. I am now having to very rapidly port this web app to typings because tsd has apparently been shut down ( DefinitelyTyped/tsd#269 (comment) ) and so our previous build process no longer runs.

Your documentation ( https://github.com/typings/typings/blob/master/docs/tsd.md ) specifically suggests running:

typings install dt~react --global --save

This doesn't work. It prints

typings ERR! message Attempted to compile "react" as a global module, but it looks like an external module. You'll need to remove the global option to continue.

I don't know what that means. However, say I remove the "--global" option. My build script now looks like:

typings install dt~jquery --global --save
typings install dt~react --save

Your documentation ( https://github.com/typings/typings ) says to "use typings/index.d.ts (in tsconfig.json or as a /// reference)." I have existing /// references to tsd.d.ts, which I change to references to index.d.ts.

/// <reference path="../typings/index.d.ts" />

I hit "make". I get 354 errors. Most of them are of the form "Cannot find name 'React'." However, there is also an error in the d.ts file installed by typings:

typings/modules/react/index.d.ts(11,1): error TS1316: Global module exports may only appear at top level.

I don't know what that means. However, if the error is in a file generated by typings, it seems like I can't possibly fix it.

Meanwhile, I am starting to get worried. There is a vague and confusing document ( https://github.com/typings/typings/blob/master/docs/external-modules.md ) linked in your README which seems to be suggesting that if react is not "global", then it is an "external module", and if it is an "external module" that means that I can no longer use /// references and must switch to ES6 style "import"s. This is extremely worrisome. Will I have to actually rewrite my code to use "import"? Does using "import" mean I will have to also use a tool such as webpack? My application does not use webpack, I just include React using <script />.

What I am trying to figure out

  • How do I get my app working?
  • If React in DefinitelyTyped has changed to no longer support <reference />: Can I somehow get a copy through typings of the old "react-global" package, the version tsd would have installed four months ago, the version that did support <reference />? I am using React 0.14.3. (I tried typings install dt~react@0.14.0 but this gave me the same non-global, non-functioning package).

Expected behaviors:

  • tsd should work.
  • typings invocations listed in the typings documentation should work.
  • typings should never install an index.d.ts file which produces errors.
  • It should be possible to use react in the ambient/global/<reference /> configuration.
  • I should not have to understand the difference between an "external" and "global" module to use typings for basic, common packages like jquery and react.
  • If I am required to understand the difference between an "external" and "global" module to use typings, the typings documentation should explain the difference clearly.
  • I should not have to alter the code of a one-year-old web app to keep up with changes in the package manager. If tsd install bleh worked a year ago, then typings install dt~bleh@oldversion should work today.

Configuration

$ tsc --version
Version 2.2.1
$ typings --version
2.1.0
@xmcclure
Copy link
Author

Note: I found this issue #766 with a similar error message. The issue is marked resolved, but the issue was never resolved. The user worked around it by switching from using typings to getting the typings through npm. My application is not currently using npm. I use the version of react.js and react-dom.js from the facebook CDN.

Is it possible to get react typings through typings?

@blakeembrey
Copy link
Member

No, it's not. There's nothing we can do from Typings, unfortunately. See #738.

@blakeembrey
Copy link
Member

should never install an index.d.ts file which produces errors

It doesn't.

I should not have to understand the difference between an "external" and "global" module

Yes, you really should learn the difference. It's not my fault DefinitelyTyped was always jank - I avoid breaking things from DefinitelyTyped but TypeScript wasn't afraid to pull that plug since it was needed for TypeScript 2.0 to evolve.

If I am required to understand the difference between an "external" and "global" module to use typings

I thought it was explained enough, but feel free to submit a PR. I'm no longer actively working on Typings since TypeScript has effectively EOL'd it with NPM @types.

I should not have to alter the code of a one-year-old web app to keep up with changes in the package manager

You don't. These changes were not from us, and any application previously using Typings would still be working since everything is pinned to commit tags. TSD has been deprecated for over a year now, and even it would keep working along. Your problem is you expect DefinitelyTyped not to have changed, not the package managers. And, in fact, I've been very explicit that I don't control DefinitelyTyped and this would occur one day - every namespace under Typings is still the same.

@xmcclure
Copy link
Author

"There's nothing we can do from Typings, unfortunately "

No, hold on, I don't believe you. What happened to the package which tsd would have installed six months ago? Was it deleted? Is it in github somewhere?

@xmcclure
Copy link
Author

And even if there's nothing you can do to make it work, you could at least remove from your README/documentation sample lines which no longer work.

@blakeembrey
Copy link
Member

It is still there, you would need to find the last commit hash where it was working. You can find this through the Typings CLI (http://api.typings.org/entries/dt/react/versions?deprecated=true). However, that doesn't mean we can fix this situation. It just means you can use old stuff.

@blakeembrey
Copy link
Member

@xmcclure Feel free to submit a PR - maybe I wasn't clear on my maintenance of the module. I'm just waiting for microsoft/types-publisher#4 to deprecate officially - something I hoped to do six months ago. Hopefully it'll be soon, but I'm happy to update the docs to reflect the current state.

@xmcclure
Copy link
Author

xmcclure commented Mar 14, 2017

"you can find this throuhg the Typings CLI… It just means you can use old stuff."

Thank you for the help, I think this url is what I was looking for… getting my existing "old stuff" to work is all I was trying to do _

@xmcclure
Copy link
Author

If anyone runs across this for future reference: Using the api.typings.org link above I was able to get circa-last-year versions of DefinitelyTyped typings of react-global, react-dom, and react. Unfortunately the react-dom package installed this way did not appear to actually export the ReactDOM object, so here I had to give up…

@xmcclure
Copy link
Author

Again for any future person reading this: My eventual solution was to remove tsd, typing and all my <reference />s and run this in my build script:

npm i @types/react-dom @types/react @types/jquery

Despite my previous fears I did not have to switch to using npm to install react itself for this, and I was able to continue using the same version of react I had been using. As long as I upgraded to TypeScript 2 this worked.

@unional
Copy link
Member

unional commented Mar 14, 2017

@xmcclure thanks for adding information for future reference. 🌷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants