npm 6.x 的install语法

220 阅读2分钟

vue3中npm 报错 npm:fork-ts-checker-webpack-plugin@^5.0.11,如果你在打包vue3项目的时候发信这个问题,说明你该升级你的Npm版本了...

下面是翻译自npm install官网的英文文档;

npm-install

概要

npm install (with no args, in package dir)
npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>
npm install <alias>@npm:<name>
npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>
npm install <tarball file>
npm install <tarball url>
npm install <folder>

aliases: npm i, npm add
common options: [-P|--save-prod|-D|--save-dev|-O|--save-optional] [-E|--save-exact] [-B|--save-bundle] [--no-save] [--dry-run]

描述

This command installs a package, and any packages that it depends on. If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist. See package-lock.json and npm shrinkwrap.

A package is:

  • a) a folder containing a program described by a package.json file
  • b) a gzipped tarball containing (a)
  • c) a url that resolves to (b)
  • d) a <name>@<version> that is published on the registry (see registry) with (c)
  • e) a <name>@<tag> (see npm dist-tag) that points to (d)
  • f) a <name> that has a "latest" tag satisfying (e)
  • g) a <git remote url> that resolves to (a)

。。。省略

npm install [<@scope>/]<name>:

Do a <name>@<tag> install, where <tag> is the "tag" config. (See config. The config's default value is latest.)

In most cases, this will install the version of the modules tagged as latest on the npm registry.

执行 @ 安装,其中是“ tag”配置。 (请参阅配置。配置的默认值为最新。) 在大多数情况下,这将在npm注册表上安装标记为最新的模块版本 latest

Example:

npm install sax

`**npm install <alias>@npm:<name>**`**:**

Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, more convenient import names for packages with otherwise long ones and using git forks replacements or forked npm packages as replacements. Aliasing works only on your project and does not rename packages in transitive dependencies. Aliases should follow the naming conventions stated in validate-npm-package-name.

在自定义别名下安装软件包。 允许并排使用多个版本的同名程序包,对于其他名称较长的程序包,使用git fork替换或派生的npm程序包作为替换,则可以更方便地导入名称。 别名仅在您的项目上起作用,并且不会在传递性依赖项中重命名程序包。 别名应遵循validate-npm-package-name中规定的命名约定。

Examples:

npm install my-react@npm:react
    npm install jquery2@npm:jquery@2
    npm install jquery3@npm:jquery@3
    npm install npa@npm:npm-package-arg

看到这里大家应该知道为什么vue3打包报错了,因为vue使用了npm 6.*的语法,给fork-ts-checker-webpack-plugin起了别名fork-ts-checker-webpack-plugin-v5  ,用来区分fork-ts-checker-webpack-plugin;见下图

"@vue/cli-plugin-typescript": { 
      "version": "4.5.11", 
      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-typescript/-/cli-plugin-typescript-4.5.11.tgz",
      "integrity": "sha512-oVv4p/gec/xqFuJOUqBxVuThk7fj2QMfoDpe6QfkWIVQU+g8JLpZvOQo0wDMoiHtURQKtqGQCwC57jkKOCufqg==",
      "dev": true,
      "requires": {
        "@types/webpack-env": "^1.15.2",
        "@vue/cli-shared-utils": "^4.5.11",
        "cache-loader": "^4.1.0",
        "fork-ts-checker-webpack-plugin": "^3.1.1",
        "fork-ts-checker-webpack-plugin-v5": "npm:fork-ts-checker-webpack-plugin@^5.0.11",
        "globby": "^9.2.0",
        "thread-loader": "^2.1.3",
        "ts-loader": "^6.2.2",
        "tslint": "^5.20.1",
        "webpack": "^4.0.0",
        "yorkie": "^2.0.0"
      },
      "dependencies": {
        "fork-ts-checker-webpack-plugin": {
          "version": "3.1.1",
          "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-3.1.1.tgz",
          "integrity": "sha512-DuVkPNrM12jR41KM2e+N+styka0EgLkTnXmNcXdgOM37vtGeY+oCBK/Jx0hzSeEU6memFCtWb4htrHPMDfwwUQ==",
          "dev": true,
          "requires": {
            "babel-code-frame": "^6.22.0",
            "chalk": "^2.4.1",
            "chokidar": "^3.3.0",
            "micromatch": "^3.1.10",
            "minimatch": "^3.0.4",
            "semver": "^5.6.0",
            "tapable": "^1.0.0",
            "worker-rpc": "^0.1.0"
          }
        }
      }
    },