bcherny/json-schema-to-typescript

`SyntaxError` while building browser bundle

GabenGar opened this issue · 2 comments

It crashes at this stage, so I assume when building a browser bundle:

> json-schema-to-typescript@13.1.2 build:browser
> browserify src/index.ts -s jstt -p tsify > dist/bundle.js

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (2:0) while parsing {project_path}\node_modules\@bcherny\json-schema-ref-parser\lib\index.js while parsing file: {project_path}\node_modules\@bcherny\json-schema-ref-parser\lib\index.js
    at DestroyableTransform.end [as _flush] ({project_path}\node_modules\insert-module-globals\index.js:114:21)
    at DestroyableTransform.prefinish ({project_path}\node_modules\readable-stream\lib\_stream_transform.js:138:10)
    at DestroyableTransform.emit (node:events:514:28)
    at prefinish ({project_path}\node_modules\readable-stream\lib\_stream_writable.js:619:14)
    at finishMaybe ({project_path}\node_modules\readable-stream\lib\_stream_writable.js:627:5)
    at endWritable ({project_path}\node_modules\readable-stream\lib\_stream_writable.js:638:3)
    at Writable.end ({project_path}\node_modules\readable-stream\lib\_stream_writable.js:594:22)
    at DestroyableTransform.onend ({project_path}t\node_modules\readable-stream\lib\_stream_readable.js:577:10)
    at Object.onceWrapper (node:events:628:28)
    at DestroyableTransform.emit (node:events:526:35)

Possibly related to building on Windows 10 with Node v20.9.0.

I've looked at the similar browserify issues but all of them seem to be unrelated:

Seeing @bcherny\json-schema-ref-parser in the logs, it's probably the problem with the build output of that fork, I'll check it out later.

So the fork doesn't even build (on windows 10 with Node 20 at least), it outputs this structure into cjs folder:

/util
  - projectDir.cjs
/package.json

And the output isn't even hidden in .gitignore.
I've checked the original repo and it builds fine.

On Ubuntu 22 and NodeJS 20 it doesn't build either with more-less the same error stack:

> json-schema-to-typescript@13.1.2 build:browser
> browserify src/index.ts -s jstt -p tsify > dist/bundle.js

(node:6168) [DEP0128] DeprecationWarning: Invalid 'main' field in '{project_path}/node_modules/find-parent-dir/package.json' of 'find-parent-dir.js'. Please either fix that or report it to the module author
(Use `node --trace-deprecation ...` to show where the warning was created)
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (2:0) while parsing {project_path}/node_modules/@bcherny/json-schema-ref-parser/lib/index.js while parsing file: {project_path}/node_modules/@bcherny/json-schema-ref-parser/lib/index.js
    at DestroyableTransform.end [as _flush] ({project_path}/node_modules/insert-module-globals/index.js:114:21)
    at DestroyableTransform.prefinish ({project_path}/node_modules/readable-stream/lib/_stream_transform.js:138:10)
    at DestroyableTransform.emit (node:events:514:28)
    at prefinish ({project_path}/node_modules/readable-stream/lib/_stream_writable.js:619:14)
    at finishMaybe ({project_path}/node_modules/readable-stream/lib/_stream_writable.js:627:5)
    at endWritable ({project_path}/node_modules/readable-stream/lib/_stream_writable.js:638:3)
    at Writable.end ({project_path}/node_modules/readable-stream/lib/_stream_writable.js:594:41)
    at DestroyableTransform.onend ({project_path}/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (node:events:628:28)
    at DestroyableTransform.emit (node:events:526:35)

EDIT: the fork does build an aforementioned setup, which means there are some missing swc binaries for windows most likely. I don't see the usual suspect anomalies in the cjs output folder, however arethetypeswrong does show there is an issue with that forked package. And even its description lines up, i.e. a hand-crafted .d.ts file with ESM syntax, which is used for both CJS and ESM entry points.