yanivz
yanivz

Reputation: 158

How to install ESlint with no npm?

I am working on enterprise computer with no internet access nor node (npm). I have downloaded ESlint manually and installed it to VS Code. Now it says that i need to use npm command for it to work, my question is how can i run ESlint globally without npm command/Node? Is it possible?

This what i get:

To use ESLint please install eslint by running npm install eslint in the workspace folder Supreme

or globally using 'npm install -g eslint'. You need to reopen the workspace after installing eslint.

after trying to set it right i get:

PS C:\inetpub\wwwroot\Supreme> eslint --init

eslint : The term 'eslint' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try

Upvotes: 4

Views: 6780

Answers (3)

qwr
qwr

Reputation: 10955

I found out my distro, Ubuntu 20.04, offers eslint through apt (although outdated, because only supports up to ES2018), so I don't need to install it through npm. Creating .eslintrc.json required me to have a package.json, however once I create the .eslintrc.* file, I can get rid of package.json.

Then I can run eslint ~/some_code.js anywhere as long as an eslintrc file is present. You can specify any eslintrc file to use by using -c, ex. eslint -c ~/.eslintrc.json some_code.js.

Sample .eslintrc.json for running code in browser, using spaces, unix linebreaks, double quotes for strings, and always semicolons:

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaVersion": 2018
    },
    "rules": {
        "indent": [
            "error",
            4
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "double"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}

Upvotes: 1

Tore Aurstad
Tore Aurstad

Reputation: 3826

I have created a Github repo for creating a tailored Eslint standalone binary here: Eslint-Standalone

This uses node, npm and pkg to build a eslint tool into a binary, such as an exe for win platform. You can then use that exe and copy it into your network at work with restrictions when it comes to npm.

Upvotes: 1

Robbie
Robbie

Reputation: 19500

npm is mostly just moving files around for you - if you want to install it without npm, just move the files around yourself.

E.g. go grab the latest release of eslint from github, copy it to your enterprise computer (network/flash drive?) and unpack it. Then call it directly using node path/to/bin/eslint.js.

If you have node.js installed it should work - if not, you'll need to use a similar approach to install that.

To execute it without prefixing the command with node, e.g. just eslint, you would need to install a .cmd wrapper alongside it. npm does this using cmd-shim

If you wanted to run it without having node.js installed, then you would need to package the node.js runtime and eslint together - options for this include pkg and nexe

To get VSCode to run eslint, you would need to setup a custom task runner by adding a tasks.js file to your project - e.g:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "eslint-fix",
      "type": "shell",
      "command": "path/to/your/packaged/eslint --fix"
    }
  ]
}

Then you can use the Tasks: Run Task command to find and execute it - or setup a shortcut - for more details see the docs https://code.visualstudio.com/docs/editor/tasks#_custom-tasks

Upvotes: 1

Related Questions