-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
resolveJsonModule with --module amd
#25755
Comments
The code that was emitted before for |
--module amd
Well it' not any different from importing the import phoneNumber from 'libphonenumber-js';
import phoneMetadata from 'libphonenumber-js/metadata.mobile.json';
console.log(phoneNumber.isValidNumber('012-345678', 'SE'));
console.log(phoneMetadata); (The only quirk was that when targeting |
aha! that is how it is working 😃. well the idea is the output the compiler should not generate invalid code silently , and not all users have a script as such, nor there is a way to tell them they need to have one. most AMD users i am aware of use a |
So I'm not allowed to import modules from Because there is no is no difference between
It used to work, the code generated was certainly just as valid as any other module imported from |
I filed a separate issue at #26020 for supporting JSON with es2015 modules. I really hope that this changes because otherwise typescript and rollup won't work well together if I want to also get things like the version from a JSON file. |
In TypeScript 2.9.1, everything work perfectly fine. To make my project works in TypeScript 3, I may need to use global definition for JSON module again. |
Unfortunately, I have to use TS 3 because of a bug in TS 2.9 where the full import path appears in the type declarations. This was fixed in TS 3 and not backported to TS 2.9. This is fine except for this issue with JSON imports. |
We also need this, or actually support for |
@mhegazy do you need more info for this issue? I'd be happy to contribute more examples. |
Adding @RyanCavanaugh and @DanielRosenwasser to this issue to give their opinion and suggest what needs to be done. |
IMO this should be considered a regression and treated as a bug. The following error check is in my way now, and I don't want to comb through my project to render it commonjs friendly when it worked fine with JSON imports till this point. |
|
@mhegazy why is this still marked as 'needs more info'? Can someone update this issue accordingly? Should we just remove the offending error check? |
@mhegazy @sheetalkamat @RyanCavanaugh and @DanielRosenwasser, can you give us an estimate of when this issue will be looked at? I hate to be naggy about this but I'm kind of in a limbo state with a lot of libraries right now. I had to update to TS 3 because of a bug in TS 2.9 but now the builds don't work anymore because of this issue (rollup doesn't produce correct code when commonjs) and I don't know whether this issue here is TS is by design and I need to find another way to import from JSON. Regardless, you are all doing amazing work and I can't thank you enough for TS! |
So it looks increasingly that just to stay up to date with typescript, I have to convert 4 projects to 'commonjs' or be stuck on 2.9 indefinitely. Do I really, really want to go there? Please can someone who is knowledgable give me an indication on where this issue is at? A clear answer is all I'm looking for... |
An alternative to switching to commonjs is to add a json typings file. You won't get type safety but at least you can build again. declare module "*.json" {
const value: any;
export default value;
} |
…t#25755 has been resolved.
can confirm that @domoritz solution works for me |
Having said that, the approach has a few disadvantages. First, you don't get type checks. Second, you might have to copy your package.json to the right location for your build system to pick it up. Lastly, you have to include the JSON typings file in all dependent projects that also use Typescript. |
I don’t get it. It was working for Esnext users and then it was broken. It’s a regression regardless of whether esnext is tracking or not, as entire projects are structured on this. This reversal requires that a fair amount of technical investment is done to satisfy a completely arbitrary restriction. @RyanCavanaugh |
This issue is getting ignored and I’m about to freeze our ts version indefinitely as well as unsubscribe from typescript issues. If this won’t be graced with a response, the status quo will do fine. |
I am on the same boat, |
Sorry for the confusion here, everyone. We didn't intend to support this scenario (the number of different flag combinations we have to think about is overwhelming!) and ended up shipping something we didn't realize was working for some subset of people. The behavior described in #25517 (comment) is what we should do now that people have taken a dependency on it. It's too far past 3.0 to backport the fix at this point, so I'd advise people to stay on 2.9 and move directly to 3.1 once it's available. Thanks! |
Thank you @sheetalkamat and @RyanCavanaugh for the fix. I look forward to the 3.1 release. |
Really appreciate the fix. Thanks all! 🥇 |
TypeScript Version: 3.1.0-dev.20180717
Search Terms: #25517
Code
Expected behavior:
The code that used to work just fine in 2.9 still works in 3.x without generating compilation errors.
Actual behavior:
The resolution of #25517 (which I'm really not happy with) not only did not fix the issue reported, it also broke our existing code referencing a json file from the
libphonenumber-js
module.Playground Link:
Related Issues: #25517
The text was updated successfully, but these errors were encountered: