Unable to execute the node executable using #!/usr/bin/env node

I've been working on creating my own npm executable, but after installing the dependency in a different project and trying to run the executable, I encountered the following error:

$ node_modules/.bin/html-linter    
: No such file or directory

Even though the file exists and has the proper node shebang at the top (I followed the same format as the tslint executable).

When I call it like this, it works perfectly:

$ node node_modules/.bin/html-linter

However, I would prefer not to have to do that every time.

My executable code snippet looks like this:

#!/usr/bin/env node

require('../lib/html-linter-cli');

The path seems correct, running '/usr/bin/env node' in my console works, and 'node --version' provides normal output.

If you're interested in installing the package from npm, it's named html-linter.

Answer №1

Take a look at the complete error message (which unfortunately seems to be hidden in your Terminal):

$ node_modules/.bin/html-linter
env: node\r: No such file or directory

The occurrence of \r indicates that there is a carriage return in the shebang line, most likely caused by Windows-style line endings (this character may have interrupted the error message in your Terminal and made it difficult to read). The file command can confirm this issue.

$ file node_modules/.bin/html-linter
node_modules/.bin/html-linter: a /usr/bin/env node script text executable, ASCII text, with CRLF line terminators

Solution: Avoid using Windows line endings whenever possible and ensure that your files are saved with Unix-style LF endings. Most good code editors will offer this configuration option.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Testing the controllers in Express is crucial for ensuring the functionality

When it comes to unit testing with Express, I've been facing some challenges due to the lack of documentation and information available online. I have discovered that I can test my routes using a library called supertest (https://github.com/visionmed ...

npm windows installation proxy problem

When setting up a proxy on Windows 7, I am using the following commands: npm config set proxy http://<username>:<password>@<proxy-server-url>:<port> npm config set https-proxy http://<username>:<password>@<proxy-serv ...

Saving numerous model records within a single POST endpoint using Mongoose, Express, and Nodejs

My Search model and Result model have a one-to-many relationship. When the user performs a search, selects helpful results, and clicks on a save button, an app.post() request is triggered. This request should save an instance of the Search along with one o ...

Obtain the index of a selected option in a Select Tag using Node.js/Express

When you make a POST request with a form in Node.js/Express For example: <select name="selectname"> <option value="value1">Value 1</option> <option value="value2" selected>Value 2</option> <option value="value3"> ...

What is the best way to locate a function (whether it be a GET, POST, etc.) within index.js using an Express router

I've been trying to set up a router in Express, following a tutorial. However, my code can't seem to find the function get/users. Interestingly, it works fine when I include it in index.js index.js : const express = require('express' ...

Not completing the npm install process

When I try to run npm install in Visual Studio Code, I keep encountering the same error message. After researching solutions, here's what I tried: Based on recommendations from Stack Overflow and error messages, I attempted to install Visual Studio C ...

Obtain the file path relative to the project directory from a Typescript module that has been compiled to JavaScript

My directory structure is as follows: - project |- build |- src |- index.ts |- file.txt The typescript code is compiled to the build directory and executed from there. I am seeking a dependable method to access file.txt from the compiled module without ...

Efficient version control and change tracking system for Mongoose database operations

I am exploring ways to automatically generate a record (Update) in MongoDB using Mongoose/Node.js/Express whenever changes are made to a document. Being new to Node.js, I am seeking advice on the most effective approach for achieving this. The envisioned ...

When using Websocket, an error message stating "Invalid frame header" will be triggered if a close message of 130 or more characters is sent

I am utilizing the ws node.js module along with html5's WebSocket. The Websocket connection is established when a user triggers an import action, and it terminates once the import is completed successfully or encounters an error. At times, the error ...

Global installation of Node modules

How do I reference globally installed node modules? For example, if I have a package.json file and I choose to install all the node modules listed in it globally (located at C:\Users\MyaccountName\AppData\Roaming\npm), how can I ac ...

Implementing html5mode in Express.js and Angular.js for cleaner URLs

I've been working on resolving the issue of avoiding # in my Angular app with an ExpressJS server-side setup. I found a solution to enable html5mode and it worked well. However, whenever there is another 'get' request to fetch data from a di ...

Encountering issues when generating png/pdf files using highcharts-export-server

I have successfully installed node.js LTS version 18.17.1 (which includes npm 9.6.7). prompt$ node Welcome to Node.js v18.17.1. prompt$ npm version npm version { npm: '9.6.7', node: '18.17.1', acorn: '8.8.2', ada: &a ...

Releasing a Node.js package to the npm registry

Looking for guidance on utilizing .ENV variables when releasing an npm package. Is it possible to include .env variables when publishing my npm package? Appreciate any help! I am currently incorporating the "dotenv" version: "^16.0.3" ...

Getting the name of parameters from Vue 3/Express

Greetings, I want to start by apologizing if the title of my question caused any confusion for those reading it. I struggled to find the right wording. The issue at hand involves a problem with sending a get request from my axios instance to my express ins ...

How can Vue listen for a Vuex commit?

Is there a method to detect when a Vuex commit occurs without having to monitor specific property changes associated with the commit? Simply knowing if a commit has taken place? I am working on a Filter component that I plan to include in an NPM package. ...

The NPM update command encountered numerous warnings but ultimately completed successfully

Recently, I dove into the world of NPM packages and encountered some issues with dependencies. Fortunately, this community provided great assistance in resolving them. However, a new challenge arose when attempting to update the CLI application. Interestin ...

Field not found in result of mongoose query

Currently, I am exploring the use of node in conjunction with the express framework and utilizing mongo as a database. The schema that I have defined looks like this : var JsonSchema = new Schema({ ...

Using Node.js to Send Ctrl+C to a Child Process in a Windows Environment

Hey there, I've been using child_process.spawn to launch a child process that runs a Python script on my Windows machine. The Python script listens for SIGINT to gracefully exit itself, but unfortunately Windows doesn't support signals and Node j ...

Exploring the capabilities of data processing in Node.js

I've been attempting to read data from a locally stored JSON file, organize it into individual JS objects, and add them to a queue. However, I'm struggling to find a way to test my parsing function to ensure it's functioning correctly. My cu ...

Deploying NodeJS applications using PM2, with support for both clustered and single instances

Consider the following scenario: The server has a scoped pm2 instance running in the /project directory A new version of the app is pushed to master branch The continuous integration (CI) system builds the new version How can I instruct CI to deploy the ...