-
Notifications
You must be signed in to change notification settings - Fork 55
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
Unable to use the library with Ionic #11
Comments
For starters, there is no index.js in json2typescript - but I don't know why Ionic expects it. I am not familiar with Ionic because I have never used it. If you want a quick fix, you can try to simple include the necessary *.ts file from our library and call it directly. I will start with Ionic in a few weeks as well, so I might fix the issue when I encounter it as well. Feel free to let me know if you know how to fix it! |
Hi Andreas, Thank you for your response. Regarding Workaround Regarding the Issue Ionic is a cross-platform hybrid mobile application framework, underneath it still uses the latest Angular version. If you can get it working for ionic it would be great as I would keep getting you enhancements quite easily. I will definitely post a solution if I find one. Whenever you get a chance to look at the issue here are the steps to reproduce that problem:
|
Well, in the web (Angular) in the end everything gets translated to JavaScript before runtime as well. You just have to make sure, the JsonConvert TypeScript file gets transpiled into JavaScript as all your other files as well. I don't know how this works in Ionic, but in Angular a simple import is enough. |
In Angular they configured Webpack to package node modules with the bundle, so the problem of not having an index.js is not raised. In Ionic you may fix your problem by importing the lib using a relative path like Hope this helps ! |
Thank you for your reply. Ideally Ionic build scripts automatically picks up 3rd party dependencies from the node_modules if you have a dependency in the code somewhere in your application pretty much the same way as angular. I tried your suggestion by providing a relative path and it worked perfectly fine However, I am still in a dilemma whether to implement your solution in my use-case. On other hand with your suggested approach, Auto-import extension won't work as it will try import to the lib as a proper npm package ( I still hope I can find a proper solution which works smoothly with my current development workflow. |
@savanvadalia The cleanest you can do IMHO is to copy the As for the problem you mention about having to type the path, I think your IDE should be able to auto import the file once it detects it in your sources (after you copied it). I don't know which IDE you use, but Webstorm does this pretty well. Don't worry, I'll be trying to fix this issue ASAP as I need this lib to work properly. |
May be I confused you, pardon my English :) I use VS-Code as an IDE and auto-import does work fine if I use I hope your fix solves my issue too 👍 |
I'll add a compiled json-convert.js to the next release. Will this suffice or is there more to do to make it work with Ionic? |
Yes it will :) If you don't mind, I'm working on a pull request on your repo, adding a compiled version and some integration / unit tests with karma. Should be done by the end of the |
@gempain I see you finished the pull request, you are a legend 🥇 Once the pull request is merged by @andreas-aeschlimann I will let you know if it solves my problem for the ionic project. |
@savanvadalia You are very welcome :) This is my first pull request, I hope it gets through ! Yes, with Typescript 2.3.4, you cannot use inner classes as it was originally done here. I wanted to change the code as few as possible while focusing on the directory structure and flows. Please let me know if this fixes your issues. Also, while waiting for the pull request, you can already test to see if it will work for you:
That's it. Now replace your relative imports with path-less ones and see if it works. You may need to restart your IDE or force it to re-index node packages (at least that's what I had to do). You should now have type definitions and the compiled version correctly set. Remember to roll-back to your relative paths until the next release of the lib comes out ;) |
Thanks @gempain I will need some more help from you despite your clear instructions. This is a bit embarrassing for me as I wasn't able to finish those steps, I have just started using git recently and coming from TFS(source control system like git) environment doesn't help me. I tried the first step in a directory and it gives below error
So I created a new git repo in the folder by Can you please help what I am doing wrong here? |
@savanvadalia My mistake, it's |
Thanks @gempain After changing But doing an npm install under my ionic from the generated .tgz file is now not recognized as a npm module. Just to highlight here previously I was able to access as a npm module. Also I don't see any Not to mention I did close my IDE and reopened it. Also I created a complete new test ionic project but still wasn't able access the npm module. |
@savanvadalia Run |
I have to admit I don't like that ValueCheckingType is an exported type, but if this is really the only way we can make this work, ok then. I will work through the pull request soon and will merge it with what I have planned for the serialization and custom converter feature. |
Don't worry, the ValueCheckingMode enum is not exported ! It's only visible within the file it is declared in :) |
True, but it needs to be explicitly imported when it is used, right? |
You are right :/ May be we should place the JsonConvert inside a Json2TypeScript module ? This way to use that value you could import |
@gempain Thanks Geoffroy I learned a lot along the way through this small but effective exercise for me. @andreas-aeschlimann I will close this issue once the pull request is merged to the master? |
@savanvadalia yup :) Always |
@andreas-aeschlimann Any updates on when @gempain 's pull request be merged? |
Sorry for being so inactive, I have been very busy and am on a 2-week holiday trip now. I will make further development right after I am back (in 1 week) because I will need the updates as well! Thanks also for @gempain to help and all your interest. |
You are very welcome :) Have fun on your vacation ! |
I'm going to close this issue, as it should be fixed in the new version. Would appreciate if you tried the current GitHub commit @gempain @savanvadalia. |
Current version works for me in Ionic and Angular projects. |
Same here :) Sorry for the delay ! |
@andreas-aeschlimann Sorry for the extended delay, great work on the new updates. Yes, I can confirm the newer version of json2typescript works fine with ionic. However, now I am running into a strange issue where the code using json2typescript breaks when running in --prod mode. Dev mode works completely fine. This could be most likely an issue with ionic build process. Although I just printing out the error below just in case if you have any inputs.
|
I don't know, maybe you can investigate what the For sure I will look into it as well in the next weeks, because I am also working on an Ionic app now. So far I haven't used the |
Here you get your exception from:
The weird thing is, the expected type should be array. But |
I am not sure whether I can debug the code in After playing a bit with ionic build process, I was able to find that the issue is with the JS optimisation part. I have opened up an issue for the same with ionic-team here Please let me know if you come across the same issue with your ionic app in |
Hi There,
Thank you for making this library, can't wait to start using it.
Just have a bit of issue using the lib.
See below error for the screenshot.
I have used the instruction provided to install the lib
npm install json2typescript
The text was updated successfully, but these errors were encountered: