ritz078 / transform

A polyglot web converter.
https://transform.tools
MIT License
8.08k stars 596 forks source link

TypeScript to JSON Schema Failing #259

Open linonetwo opened 3 years ago

linonetwo commented 3 years ago

JSON.parse: unexpected character at line 1 column 1 of the JSON data

https://transform.tools/typescript-to-json-schema

Screen Shot 2020-12-07 at 1 01 10 AM

ritz078 commented 3 years ago

Sadly this breaks only in production and works fine locally. While I work on a fix, you can run this locally if that's a blocker.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

noxasaxon commented 3 years ago

is this actually a wontfix?

linonetwo commented 3 years ago

How can we help you debug this @ritz078 ?

ritz078 commented 3 years ago

is this actually a wontfix?

No. I fixed this locally but this breaks in production. I haven't been able to pinpoint the actual reason.

How can we help you debug this @ritz078 ?

This is mostly due to the unavailability of lib.d.ts is production env but I don't know why it isn't available.

jfsiii commented 3 years ago

I fixed this locally

@ritz078 do you mean a) you saw this failure locally, made a change that fixed it locally, but it's still broken in prod or b) things work locally but fail in production

because I can only do (b).

I also don't know what's unique about this route. Why isn't this failing for other (all?) routes?

ritz078 commented 3 years ago

I know this works locally but not on production. the package used for this conversion looks for lib.d.ts which it isn't able to find in production

ritz078 commented 3 years ago

I think the reason it is not working is because the API needs filesystem to work but vercel is serverless. The only solution I can think of right now is to either move transform to something like heroku or just move this particular API to heroku.

I am thinking of doing the latter.

linonetwo commented 3 years ago

Is that server close source or written in other language? Will it be possible to run in frontend? If it requires nodejs, there are some virtual fs that can run in the browser.

ritz078 commented 3 years ago

https://github.com/ritz078/transform/blob/master/pages/api/typescript-to-json-schema.ts is the API code that is deployed on vercel as a serverless function. The client-side uses this API. As you can see it does filesystem operation which doesn't work when deployed as a lambda and works locally since it has access to the filesystem.

We can create a separate directory that has a server that gets deployed to Heroku. transform.tools can use those APIs from there.

Will it be possible to run in frontend? If it requires nodejs, there are some virtual fs that can run in the browser.

Yes, it should be possible but it will be too much work as we will have to run both the typescript compiler and the converter on the browser. Both do not support this by default. Also, that will be a lot of JS on the browser-side making the page load slow.

ShivnathGupta commented 2 years ago

Typescript should stay on devDependencies in package.json

https://github.com/vercel/pkg/issues/572#issuecomment-440978846

may be it works

Darkle commented 2 years ago

Bump

ritz078 commented 2 years ago

@ShivnathGupta That didn't work https://github.com/ritz078/transform/pull/329

linonetwo commented 1 year ago

Can you try some vitrual fs to run this package? https://github.com/vfile/vfile#vfiletostringencoding this ecosystem has many packages.