我正在构建一个包(让我们称之为项目a),我正试图包含在另一个项目中(项目b)。
在项目b中,我在package.json
中有这个...
"dependencies": {
"a": "C:\\Users\\myuser\\AppData\\Roaming\\npm\\node_modules\\a"
},
...
但是当我在项目b中运行npm install
时,我收到错误:
npm ERR! notarget No compatible version found: 1@'C:\Users\myuser\AppData\Roaming\npm\node_modules\a'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6"]
发布版本1.0.0 - 1.0.6(虽然不起作用)。
为什么npm install不查看我指定的路径而不是查看NPM公共回购?
答案 0 :(得分:1)
因为这不是npm识别的一种来源。见package.json(5):
dependencies
Dependencies are specified with a simple hash of package name to ver‐
sion range. The version range is a string which has one or more
space-separated descriptors. Dependencies can also be identified with
a tarball or git URL.
Please do not put test harnesses or transpilers in your dependencies
hash. See devDependencies, below.
npm help See semver for more details about specifying version ranges.
· version Must match version exactly
· >version Must be greater than version
· >=version etc
· <version
· <=version
· npm help ~version "Approximately equivalent to version" See
semver
· npm help ^version "Compatible with version" See semver
· 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
· http://... See 'URLs as Dependencies' below
· * Matches any version
· "" (just an empty string) Same as *
· version1 - version2 Same as >=version1 <=version2.
· range1 || range2 Passes if either range1 or range2 are satisfied.
· git... See 'Git URLs as Dependencies' below
· user/repo See 'GitHub URLs' below
在npm link
内运行C:\Users\myuser\AppData\Roaming\npm\node_modules\a
,并在package.json
中设置常规依赖关系。
答案 1 :(得分:0)
我能够通过在我想要使用依赖项的项目中运行npm install C:\Users\myuser\AppData\Roaming\npm\node_modules\a
来安装本地构建的依赖项。