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

[Bug]: Error when using the binary (v2.1.0) #1936

Closed
ReneWerner87 opened this issue Apr 23, 2024 · 9 comments
Closed

[Bug]: Error when using the binary (v2.1.0) #1936

ReneWerner87 opened this issue Apr 23, 2024 · 9 comments

Comments

@ReneWerner87
Copy link

hi i have problems with the binary for the last release

Version
https://github.com/vega/ts-json-schema-generator/releases/tag/v2.1.0

image
Click here for the commands

With version 2.0.1

npx ts-json-schema-generator@2.0.1 --help
Options:
  -p, --path <path>              Source file path
  -t, --type <name>              Type name
  -i, --id <name>                $id for generated schema
  -f, --tsconfig <path>          Custom tsconfig.json path
  -e, --expose <expose>          Type exposing (choices: "all", "none", "export", default: "export")
  -j, --jsDoc <extended>         Read JsDoc annotations (choices: "none", "basic", "extended", default: "extended")
  --markdown-description         Generate `markdownDescription` in addition to `description`.
  --functions <functions>        How to handle functions. `fail` will throw an error. `comment` will add a comment. `hide` will treat the function like a NeverType or HiddenType. (choices: "fail", "comment", "hide", default: "comment")
  --minify                       Minify generated schema (default: false)
  --unstable                     Do not sort properties
  --strict-tuples                Do not allow additional items on tuples
  --no-top-ref                   Do not create a top-level $ref definition
  --no-type-check                Skip type checks to improve performance
  --no-ref-encode                Do not encode references
  -o, --out <file>               Set the output file (default: stdout)
  --validation-keywords [value]  Provide additional validation keywords to include (default: [])
  --additional-properties        Allow additional properties for objects with no index signature (default: false)
  -V, --version                  output the version number
  -h, --help                     display help for command

With version 2.1.0

npx ts-json-schema-generator@2.1.0 --help
node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /Users/wernerr/.npm/_npx/2fafbd5150af9509/node_modules/ts-json-schema-generator/bin/ts-json-schema-generator. Loading extensionless files is not supported inside of "type":"module" package.json contexts. The package.json file /Users/wernerr/.npm/_npx/2fafbd5150af9509/node_modules/ts-json-schema-generator/package.json caused this "type":"module" context. Try changing /Users/wernerr/.npm/_npx/2fafbd5150af9509/node_modules/ts-json-schema-generator/bin/ts-json-schema-generator to have a file extension. Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"ts-json-schema-generator":"./bin/ts-json-schema-generator.js"}}
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:605:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at #createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
@domoritz
Copy link
Member

Works for me. Make sure you have a new enough node version. I have v20.12.2.

❯ npx ts-json-schema-generator --help
Need to install the following packages:
ts-json-schema-generator@2.1.0
Ok to proceed? (y) y
(node:17662) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Usage: ts-json-schema-generator [options]

Options:
  -p, --path <path>              Source file path
  -t, --type <name>              Type name
  -i, --id <name>                $id for generated schema
  -f, --tsconfig <path>          Custom tsconfig.json path
  -e, --expose <expose>          Type exposing (choices: "all", "none", "export", default: "export")
  -j, --jsDoc <extended>         Read JsDoc annotations (choices: "none", "basic", "extended", default: "extended")
  --markdown-description         Generate `markdownDescription` in addition to `description`.
  --functions <functions>        How to handle functions. `fail` will throw an error. `comment` will add a comment. `hide` will treat the function like a NeverType or HiddenType. (choices: "fail",
                                 "comment", "hide", default: "comment")
  --minify                       Minify generated schema (default: false)
  --unstable                     Do not sort properties
  --strict-tuples                Do not allow additional items on tuples
  --no-top-ref                   Do not create a top-level $ref definition
  --no-type-check                Skip type checks to improve performance
  --no-ref-encode                Do not encode references
  -o, --out <file>               Set the output file (default: stdout)
  --validation-keywords [value]  Provide additional validation keywords to include (default: [])
  --additional-properties        Allow additional properties for objects with no index signature (default: false)
  -V, --version                  output the version number
  -h, --help                     display help for command

@domoritz domoritz closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
@ReneWerner87
Copy link
Author

ReneWerner87 commented Apr 23, 2024

@domoritz
in your package json you say that the software should be usable with node 18 and higher

i think you should also adapt the package json if you can only use the software with the latest version

"engines": {
"node": ">=18.0.0"
},

it also does not work with version 20
not working with v20.4.0
image

working with v21.4.0
image

@domoritz
Copy link
Member

Oh weird. I didn't test the other versions (but should have). I'll bump the minimum requirement to make it correct. Thanks for trying the different versions!

@domoritz domoritz reopened this Apr 23, 2024
@ReneWerner87
Copy link
Author

ReneWerner87 commented Apr 23, 2024

v2.0.1...v2.1.0#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

Unknown file extension "" for ../node_modules/ts-json-schema-generator/bin/ts-json-schema-generator. 
Loading extensionless files is not supported inside of "type":"module" package.json contexts. 
The package.json file ../node_modules/ts-json-schema-generator/package.json caused this "type":"module" context. 
Try changing ../node_modules/ts-json-schema-generator/bin/ts-json-schema-generator to have a file extension. 
Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"ts-json-schema-generator":"./bin/ts-json-schema-generator.js"}}

means that if type: module is used, all files with extensions must be used

"bin": {
"ts-json-schema-generator": "./bin/ts-json-schema-generator"
},

so why not link the js file from the dist
../dist/ts-json-schema-generator.js

@ReneWerner87
Copy link
Author

actually npm is only bothered by the missing extension for the binary resource

@domoritz
Copy link
Member

https://github.com/vega/ts-json-schema-generator/blob/fbb72f4e4267b428f9135e03a2f0f5bc39a0a6e9/bin/ts-json-schema-generator doesn't have an extension but imports a file with an extension. Are you saying we might fix the issue by adding the extension?

@ReneWerner87
Copy link
Author

https://github.com/vega/ts-json-schema-generator/blob/fbb72f4e4267b428f9135e03a2f0f5bc39a0a6e9/bin/ts-json-schema-generator doesn't have an extension but imports a file with an extension. Are you saying we might fix the issue by adding the extension?

yes excatly, thats what the error message is saying

@domoritz
Copy link
Member

Sweet. 2.1.1 works again. Thanks for digging into the issue.

@ReneWerner87
Copy link
Author

thx its solved

image

working with v18, v20 ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants