Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed: For making TS notebook in Windows#444

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
aakash-a-dev wants to merge7 commits intosrcbookdev:main
base:main
Choose a base branch
Loading
fromaakash-a-dev:windows-working

Conversation

aakash-a-dev
Copy link
Contributor

Documentation for Fixingspawn npm ENOENT Error withpnpm dlx

Issue Overview

The errorspawn npm ENOENT occurred when trying to spawn atsserver instance usingnpx in a Node.js script. This error typically happens whennpm is either missing or not found in the system'sPATH, which is required fornpx to function correctly. Althoughnpx is supposed to work independently, it relies onnpm being available in the environment. Since the project is usingpnpm as the package manager, the solution is to usepnpm dlx instead ofnpx.


Before Resolving the Issue the Error

Error

After Resolving the Issue the Error

Output-2

image

How I Resolved the Issue

  1. Replacenpx withpnpm dlx:

    The command that spawns thetsserver instance was originally usingnpx:

    constchild=spawn('npx',['tsserver'],{cwd:options.cwd,shell:true});

    This was changed to usepnpm dlx to make it compatible withpnpm:

    constchild=spawn('pnpm',['dlx','tsserver'],{cwd:options.cwd,shell:true});

    Thepnpm dlx command is similar tonpx but usespnpm to run the specified package without requiring global installation. It ensures thatpnpm is handling the execution, avoiding thespawn npm ENOENT error.


Changes Made topackage.json

No changes were directly made topackage.json to resolve the error. However, to ensure thatpnpm dlx can be used smoothly, make sure the following:

  1. Addedrimraf Dependency:

    "devDependencies": {"rimraf":"^6.0.1",...}

Conclusion

By switching fromnpx topnpm dlx, thespawn npm ENOENT error was resolved. This solution is optimal for projects usingpnpm as the package manager, ensuring compatibility and proper execution of thetsserver without relying onnpm's presence in the environment.

PS: This solution doesn't turn off the server, which was mentioned in the issue, and it also gives the output in my Windows system.

Fix:#297

@@ -44,8 +44,9 @@ export class TsServers {
// created, the dependencies are not installed and thus this will
// shut down immediately. Make sure that we handle this case after
// package.json has finished installing its deps.
const child = spawn('npx', ['tsserver'], {
const child = spawn('pnpm', ['dlx' ,'tsserver'], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We don't want to do this, becausepnpm is a dependency for dev, but not for users. This would require our users to have pnpm installed.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ooo okay, I didn't think that way. I will look into this further. Thank you!

@aakash-a-dev
Copy link
ContributorAuthor

This approach ensures portability and compatibility by directly resolving thetsserver binary from the project'snode_modules, avoiding reliance on global tools likepnpm ornpx.

Key Features of the Solution

  1. No Global Dependencies:

    • Avoids relying on tools likepnpm ornpx, which require global installation. Only depends on the localnode_modules directory.
  2. Cross-Platform Compatibility:

    • Automatically resolves totsserver.cmd on Windows andtsserver on Linux/macOS, ensuring it works across all operating systems.
  3. Version Consistency:

    • Always uses thetypescript version installed in the project, ensuring consistency between development environments and deployments.
  4. Shell-Free Execution:

    • Directly runs thetsserver binary without relying on shell commands, improving security and reducing potential issues.

Output

image

image

I hope this solution will be helpful for dev and end user both!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nichocharnichocharnichochar left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Creating ts srcbook on windows
2 participants
@aakash-a-dev@nichochar

[8]ページ先頭

©2009-2025 Movatter.jp