-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
automatic module resolution for JPSM packages #6012
Comments
JSPM resolution does not seem to be a simple task to do statically. #5039 should allow you to add to the configuration an override for resolving angular2, would that be sufficient? |
I'm not sure if it would work. |
Where do you see problems with static resolution?
This means if we can locate this file and parse it we know that |
the difference between node module resolution and JSPM is that node rules are exactly specified whereis JSPM resolution logic can only be reconstructed from the implementation (and implementation has several augmentations during the last year). I can see TypeScript having support for JSPM module resolution after it will be stabilized and specified otherwise there is a risk that TypeScript will always be one step behind chasing down SystemJS and this will be an endless source of issues with the same origin "TypeScript cannot find something that SystemJS can". |
Would it be possible to specify a resolution plugin and the plugin implementation is managed by jspm or someone closer on that end? I have the same need (as everyone using typescript with jspm should). |
currently module resolution is customizable if you use compiler API, we don't support loading user defined resolvers when using command line compiler. This is something that we have in our backlog but the size of this workitem is quite large (it should just work not only in command line compiler but also in all editors we officially support) |
Indeed. From what you are saying, is it correct that in order to have editor support (
Thanks, |
In theory it is possible however keep in mind module resolution in editor and in compiler should be consistent otherwise we'll get quite annoying behavior when compiler cannot find some module that editor can discover just fine and vice versa. |
Agree. Currently that is exactly what annoys me as systemjs/jspm can discover and run application correctly but the editor and tsc command line compiler cannot. |
+1, this is really pushing me to consider letting go of JSPM :( |
+1, Agree, modules from jspm_packages should be resolved by TSC and the editors. |
To put my two cents on the discussion: My work around is to create definitions files for the jspm library with a top level declaration module for instance: File notify.d.ts
File common.d.ts
File components/ca.d.ts
That way a import for 'common/components/ca' is resolved
Problems:
I wish the javascript module community had put the pride beside and had learned something with old dog java, and have made that thing less cumbersome. Java import's are way more stable and predictable, not ideal, and for sure not the best, but work very good with external libraries. The javascript module standards forget distribution and package as a crucial design |
I would love to see this feature implemented as its the only thing that needs a workaround in our Angular 2 setup (apart from the hopefully soon released jspm 0.17). |
Link to an issue on stackoverflow that show's what we get in vscode and visual studio 2015 because typescript doesn't know how to resolve jspm packages: |
+1 - this is really a pity as it felt that systemjs was the anointed package manager for Angular2, together with Typescript, but if they don't all play nicely together.... |
Would definitely like to see this solved. FWIF, it's still possible to use it properly with a bit of a workaround. To add to the one described by @giovannicandido above, we are using a combination of the Typings project (formerly TSD) and npm. This is only required for development time IDE support. Check out our angular2-redux-example example project for details. Run "npm install" and "npm typings" to get all types to be recognised properly in your IDE. |
|
Our team/company has run up against this issue as well. We've been evaluating all of our options for frontend package management, and it really is JSPM that seems to be the best fit for our needs. However, we feel that we get more out of typescript, especially the IDE features, than we do out of the JSPM package management, which due to this issue means not using JSPM. We are damned if we do, damned if we don't, we either get to use our best option for development at the cost of our best package management option, or vise versa. We have also experimented with the workaround suggested earlier, where we continue to use JSPM but also install via NPM for the IDE side. Then we either wait until this issue is addressed, or ideally help develop a solution. Once the solution is in place, we remove the need to install the duplicate package just for the IDE support. I mostly wanted to weigh in to see if anybody has any work started on this that we could help contribute to, or if at this point we are best off starting our own experiments to address this, either something that works just for our company's workflow, or an actual PR to the community to help address it for everyone. EDIT: I can see that I have a lot of reading to do in the other two linked issues, as at least the first one is a formal proposal as to how this might work. This is good to see. |
As @mhegazy adds "needs proposal" to this thread, we can discuss on how to get this done. To summarize, there are three parties that needs module resolution:
|
I thought that this PR would solve the problem for the tsc part but maybe I misunderstood. |
@unional It universally configures a package for jspm. Here are docs for how it works: https://github.com/jspm/registry/wiki/Configuring-Packages-for-jspm If you have any other questions feel free to email me (I don't want to clog up everyones notifications). |
@jakeNiemiec thanks. If I have other questions, will email you on that. The problem is we need to provide If the typings is in Also, |
@unional however, the index.d.ts does not exist in the jspm_packages/npm/[email protected] please advise thanks |
@sliultron , |
Would be great if TypeScript either maintained first-class support for JSPM and included it as part of their Q/A or developed/maintained their own JSPM-like module management so we could get an integrated solution for installing, referencing and bundling TypeScript modules. After multiple Currently TypeScript can't use definitions that are bundled with the package and installed with JSPM. So package authors are forced to maintain a parallel If TypeScript isn't going to have first-class support for JSPM, what's the recommended dev workflow for referencing and bundling TypeScript modules? Should we reference every npm package we want to use in |
My recommendation is to add a |
@mhegazy I think you may have missed the gist of the comment you quoted. It's talking about packages with native type definitions and not |
sure. i do not see them different, really. you can have a devDepenency on these as well just for type declarations.
that is correct, since the compiler does not understand JSPM modules naively , and this is what this issue is tracking. ideally the compiler will do this for you. but mean while you can add a |
@mhegazy No worries, thanks. I just thought you had misread from your comment being explicitly about |
would setting |
Good point, sounds like that should work by combining Side note: The handbook font sizing really shouldn't use |
Paths work for aliasing certain modules but they are difficult to maintain and only a partial solution as they fail on constructs like /// <reference types="dependency" /> Because we can redirect the directory structure to point at the packages folder but cannot alias the actual reference because it's an @types reference. That said, the real difficulty is in maintaining all the versionsed paths. It would be helpful if we could specify wildcards in {
"paths": {
"moment" : [
"jspm_packages/npm/moment*/index"
]
}
} could be used to match It's only a solution because it doesn't deal with the transitive dependency issue that jspm solves but it would go a long way in making a lot of scenarios easier. |
Adding this to my devDependencies in package.json worked for me. Only problem is you have to be specific on the package names :( "@angular/common": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/compiler": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/core": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/forms": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/http": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/platform-browser": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/platform-browser-dynamic": "file:jspm_packages/npm/@angular/[email protected]",
"@angular/router": "file:jspm_packages/npm/@angular/[email protected]", It would work similar for any @type npm libraries as well I am fairly sure. |
You can use https://github.com/charto/cbuild to create a SystemJS bundle from |
Yeah, definitely agreeing with this. Ecosystem needs to come together and I would love for JSPM & SystemJS to play nicely. |
@atrauzzi I really want to see this. Is there something in JSPM specifically that you feel is out of balance here? From my point of view, the versioned folders approach has a lot of advantages. The primary disadvantage is in fact the impedance mismatch between JSPM and TypeScript but I would appreciate any thoughts you might have on things that could be improved on the JSPM side as they pertain to this issue. |
The biggest problem is going to be that JSPM isn't the same final structure as nodejs and that has loader implications. Implications that most tooling has now come to agree are the one true way. In the past, anything that tries to compete with a community recognized standard has typically lost. Quite soundly. If we look at why and how in this specific case, we have to understand that both JSPM and TypeScript are subsets of the nodejs community overall. But yeah, I entirely agree, JSPM got a lot of things right. But we have yarn now, and we've got |
When it works JSPM is great so it would be a shame if JSPM remained unsupported. It appears the latest jspm@beta has broken integration with TypeScript again and after wasting some time permutating through different configurations I've had to pin it to an older version of jspm@beta. It would be nice to see some clarification from the TypeScript team if JSPM is going to be a supported configuration and if there are plans to provide native support and get some much needed Q/A love? or if the TypeScript team are focusing on a different supported configuration and what the recommended configuration should be? i.e. npm/webpack? It would help in deciding which approach to adopt that's well supported and will continue to work in future. |
@mythz FYI it is probably due to this: systemjs/systemjs#1587 |
Has the situation changed in the past year? I see the proposal for resolution plugins was closed, and the preference is to simply work with SystemJS "out-of-the-box". Is there another issue I can track or that blocks this? |
@mqudsi you have this coming down the pipeline: https://github.com/nodejs/modules |
I'm trying to use angular2 as a JSPM package.
When I'm doing something like
import {bootstrap, Component, Input} from 'angular2/angular2';
in my code then typescript complains that it can't find the definitions and I don't get any code completions.
The workaround is to install angular2 also as a npm package and set moduleResolution to node. However this seems not optimal, because now I have two dependencies whose versions need to be aligned.
I guess tsc could resolve the modules for jspm/systemjs similar to how it already can do it for node. E.g. look up package.json, config.js and use the pathes from there the locate to type definitions inside the jspm_packages folder.
Not really sure if this is covered by #5039 and #5728.
The text was updated successfully, but these errors were encountered: