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

./bin/dev.js throws ERR_UNKNOWN_FILE_EXTENSION on Node 20 #817

Closed
bader-nasser opened this issue Sep 9, 2023 · 11 comments · Fixed by #818
Closed

./bin/dev.js throws ERR_UNKNOWN_FILE_EXTENSION on Node 20 #817

bader-nasser opened this issue Sep 9, 2023 · 11 comments · Fixed by #818
Labels
bug Something isn't working

Comments

@bader-nasser
Copy link

After cloning the project and installing the deps using pnpm, running node ./bin/dev.js help does not show the commands!

Also, when I change any thing in the commands (e.g. description) and run node ./bin/dev.js help hello, I don't get the new values.

@git2gus
Copy link

git2gus bot commented Sep 9, 2023

Git2Gus App is installed but the .git2gus/config.json doesn't exist.

@mdonnalley
Copy link
Contributor

@bader-nasser Both issues are due to using node. The dev script depends on ts-node to transpile the project at runtime (https://github.com/oclif/hello-world-esm/blob/main/bin/dev.js#L1). But by specifying node you're telling the script to ignore the ts-node shebang at the top of the file and use node instead.

@bader-nasser
Copy link
Author

@mdonnalley I added these scripts and used them with @oclif/core v3 & v2

    "dev": "ts-node ./bin/dev.js",
    "dev2": "./bin/dev.js",

but still nothing is working!

@mdonnalley
Copy link
Contributor

mdonnalley commented Sep 11, 2023

@bader-nasser my bad - I forgot that support for auto-transpiling local plugins hasn't been merged yet. It's being added in this PR: #779

In the meantime, you'll need to compile your changes first before executing the plugin.

Also important to note that auto-transpiling ESM plugins will only be supported when developing the plugin from the plugin directory. In other words, bin/dev.js will auto-transpile but if you were to link the plugin to another plugin, it will not work. More context here.

@bader-nasser
Copy link
Author

For the time being I switched back to v2 and I may wait a lil' bit before using v3 again! Thank you.

@bader-nasser
Copy link
Author

@mdonnalley I upgraded to latest deps and found the dev bin. is working with:

#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

not:

#!/usr/bin/env ts-node

and I don't know why!

I run it using npm script: "app-dev": "./bin/dev.js",

https://github.com/bader-nasser/pdftools/blob/main/bin/dev.js

@mdonnalley
Copy link
Contributor

mdonnalley commented Oct 10, 2023

@bader-nasser can you elaborate on what you're seeing? I just checked out your repo, ran pnpm install, updated the bin/dev.js script to use ts-node and it seems like everything is working as expected

@bader-nasser
Copy link
Author

@mdonnalley It works with node 18 and causes an error with node 20!

I used pnpm with and without the following in .npmrc:

shamefully-hoist = true
public-hoist-pattern[]=*

as well as using npm and got the following error when using ts-node in the shebang:

$ npm run app-dev -- e -h # and pnpm app-dev e -h
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/compress/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(Use `node --trace-warnings ...` to show where the warning was created)
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/convert/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/extract/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/merge/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/process/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/repair/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/uncompress/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
(node:31017) [ERR_UNKNOWN_FILE_EXTENSION] TypeError Plugin: @bader-nasser/pdftools: Unknown file extension ".ts" for .../src/commands/update-metadata/index.ts
module: @oclif/core@3.0.4
task: cacheCommand
plugin: @bader-nasser/pdftools
root: .../pdftools
See more details with DEBUG=*
Error: Command e not found.
    at error (.../node_modules/@oclif/core/lib/errors/index.js:26:15)
    at HelpClass.showHelp (.../node_modules/@oclif/core/lib/help/index.js:221:28)
    at run (.../node_modules/@oclif/core/lib/main.js:68:20)
    at async file:///.../bin/dev.js:4:1

@mdonnalley mdonnalley transferred this issue from oclif/hello-world-esm Oct 10, 2023
@mdonnalley mdonnalley added the bug Something isn't working label Oct 10, 2023
@git2gus
Copy link

git2gus bot commented Oct 10, 2023

This issue has been linked to a new work item: W-14270164

@mdonnalley
Copy link
Contributor

@bader-nasser I transferred this issue to @oclif/core since this issue will be more visible to others here.

It seems that node 20 introduced a breaking change to the ESM loader hooks, which affects ts-node's ability to transpile ESM code.

Custom ESM loader hooks run on dedicated thread
ESM hooks supplied via loaders (--experimental-loader=foo.mjs) now run in a dedicated thread, isolated from the main thread. This provides a separate scope for loaders and ensures no cross-contamination between loaders and application code.

Source

ts-node issue: TypeStrong/ts-node#1997

Obviously, there's not much we can do on the oclif side to fix this. The best we'll be able to do is provide a better error message and provide a couple workarounds:

Workarounds

  • Downgrade to Node 19 or older
  • Replace ts-node in bin/dev.js with #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

@mdonnalley mdonnalley changed the title ./bin/dev.js does not seem to work ./bin/dev.js throws on Node 20 Oct 10, 2023
@mdonnalley mdonnalley pinned this issue Oct 10, 2023
@mdonnalley mdonnalley changed the title ./bin/dev.js throws on Node 20 ./bin/dev.js throws ERR_UNKNOWN_FILE_EXTENSION on Node 20 Oct 10, 2023
@bader-nasser
Copy link
Author

great. I'm glad that the root issue is identified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants