Skip to content
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

SyntaxError while building browser bundle #570

Closed
GabenGar opened this issue Jan 15, 2024 · 2 comments
Closed

SyntaxError while building browser bundle #570

GabenGar opened this issue Jan 15, 2024 · 2 comments
Labels
external This is an issue with a library that we depend on

Comments

@GabenGar
Copy link

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.

@GabenGar
Copy link
Author

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.

@GabenGar
Copy link
Author

GabenGar commented Jan 21, 2024

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.

@bcherny bcherny added the external This is an issue with a library that we depend on label Mar 2, 2024
@bcherny bcherny closed this as completed Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This is an issue with a library that we depend on
Projects
None yet
Development

No branches or pull requests

2 participants