transform icon indicating copy to clipboard operation
transform copied to clipboard

TypeScript to JSON Schema Failing

Open linonetwo opened this issue 4 years ago • 14 comments

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

linonetwo avatar Dec 06 '20 17:12 linonetwo

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.

ritz078 avatar Dec 12 '20 09:12 ritz078

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.

stale[bot] avatar Feb 10 '21 11:02 stale[bot]

is this actually a wontfix?

noxasaxon avatar Apr 26 '21 18:04 noxasaxon

How can we help you debug this @ritz078 ?

linonetwo avatar Apr 27 '21 04:04 linonetwo

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.

ritz078 avatar Apr 27 '21 07:04 ritz078

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?

jfsiii avatar Apr 28 '21 13:04 jfsiii

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 avatar Apr 28 '21 20:04 ritz078

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.

ritz078 avatar Jun 26 '21 19:06 ritz078

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.

linonetwo avatar Jun 27 '21 04:06 linonetwo

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.

ritz078 avatar Jun 27 '21 14:06 ritz078

Typescript should stay on devDependencies in package.json

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

may be it works

ShivnathGupta avatar Mar 21 '22 09:03 ShivnathGupta

Bump

Darkle avatar May 20 '22 05:05 Darkle

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

ritz078 avatar May 28 '22 18:05 ritz078

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

linonetwo avatar May 28 '23 12:05 linonetwo