Pana / nrm

NPM registry manager, fast switch between different registries: npm, cnpm, nj, taobao
MIT License
2.79k stars 244 forks source link

nrm not work #105

Closed changyongyong closed 2 years ago

changyongyong commented 2 years ago

i run code "nrm -v" on mac pro m1 result: [ internal/modules/cjs/loader.js:456 throw e; ^ Error: Cannot find module '/usr/local/lib/node_modules/nrm/node_modules/npm/index.js' at createEsmNotFoundErr (internal/modules/cjs/loader.js:929:15) at finalizeEsmResolution (internal/modules/cjs/loader.js:922:15) at resolveExports (internal/modules/cjs/loader.js:450:14) at Function.Module._findPath (internal/modules/cjs/loader.js:490:31) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:93:18) at Object. (/usr/local/lib/node_modules/nrm/cli.js:6:13) at Module._compile (internal/modules/cjs/loader.js:1085:14) { code: 'MODULE_NOT_FOUND', path: '/usr/local/lib/node_modules/nrm/node_modules/npm/package.json' } ]

springeye commented 2 years ago

me too

CaptainOfPhB commented 2 years ago

根据提示 path: '/usr/local/lib/node_modules/nrm/node_modules/npm/package.json' 看了下 npm(npm: "latest") 包中确实没有在 package.json 文件中 main 字段定义的 index.js 文件,因此报错了。

nrm 所依赖的 npm 版本为 latest,所以下载了 8.0.0 版本,其目录结构如下:

LICENSE
README.md
bin
docs
lib
man
node_modules
package.json

package.json 文件内容为:

{
  "main": "./index.js"
}

可以看出确实没有 index.js,所以 cli.jsvar npm = require("npm") 语句会报错。

这个问题应该是 npm 包的问题,可以暂时把 nrm 中依赖的 npm 版本降级一下,以解决 index.js 文件不存在。

PS:看了下同事的 npm 依赖,package.json 中的 version 为 6.14.0,是可以正常运行的

sunzhangchang commented 2 years ago

我通过将 ./index.js 修改为 ./lib/npm.js 解决了该问题(nrm可以运行)。

要将 package.jsonexports 中的两个 ./index.jsmain 中的同时改为 ./lib/npm.js

changyongyong commented 2 years ago

根据提示 path: '/usr/local/lib/node_modules/nrm/node_modules/npm/package.json' 看了下 npm(npm: "latest") 包中确实没有在 package.json 文件中 main 字段定义的 index.js 文件,因此报错了。

nrm 所依赖的 npm 版本为 latest,所以下载了 8.0.0 版本,其目录结构如下:

LICENSE
README.md
bin
docs
lib
man
node_modules
package.json

package.json 文件内容为:

{
  "main": "./index.js"
}

可以看出确实没有 index.js,所以 cli.jsvar npm = require("npm") 语句会报错。

这个问题应该是 npm 包的问题,可以暂时把 nrm 中依赖的 npm 版本降级一下,以解决 index.js 文件不存在。

PS:看了下同事的 npm 依赖,package.json 中的 version 为 6.14.0,是可以正常运行的

骨骼上搜了下,确实版本更新导致东西没了,版本配不上了,哎,node生态感觉要被玩坏了,这种只管向前跑,不管后边的最终,就自己在前边跑的嗨,没人跟了

Hioolong commented 2 years ago

same issue

nmsn commented 2 years ago

+1

i5ting commented 2 years ago
hanalice commented 2 years ago

我是在win10 上安装了node 14.4.0, npm 6.14.5,使用npm install -g nrm后,发生如上报错。经排查,确实发现nrm 的依赖的npm@latest 的package.json 种main 里面是.index.js,而package.json所在目录下面却没有index.js,和 @changyongyong 一致,同时将 package.json 的 exports 中的两个 ./index.js 和 main 中的同时改为 ./lib/npm.js 和 @sunzhangchang 一致,done

感谢以上两位!

hanalice commented 2 years ago

建议名称修改成nrm ls 执行后报错 Error: Cannot find module ’npm‘, 更容易大家搜索问题

liruifengv commented 2 years ago

npm 8.0 以上已经不支持使用 require('npm')了, https://github.com/npm/cli/commit/a13d9d53ddf3e0f52f4a39fe116653bf40cf99e5, 这个提交增加了 index.js,然而发布版本时,没有在 package.json 的 files 中添加,导致这个问题。也已经被修复了,https://github.com/npm/cli/pull/3874/files

修复之后,如果 nrm 使用 8.0以上 npm,就会报错,Error: The programmatic API was removed in npm v8.0.0。要不 nrm 继续使用 8.0 以下的 npm,要不就需要修改 require('npm')写法。

ImADrafter commented 2 years ago

Due to https://github.com/Pana/nrm/pull/106, a fresh install worked for me:

YeWills commented 1 year ago

npm 6.14.13; node 14.17.0; 先报了一个 internal/modules/cjs/loader.js:456 错误; 于是把 nrm 降到 2021年左右的版本; 于是报错: Error: The programmatic API was removed in npm v8.0.0。 于是查看 cat /Users/olgman/.nvm/versions/node/v14.17.0/lib/node_modules/nrm/package.json
"dependencies": { "npm": "latest" },

cat /Users/olgman/.nvm/versions/node/v14.17.0/lib/node_modules/nrm/node_modules/npm/package.json npm 是 9.+的版本。

解决方案: 使用了一个 2017年版的nrm,解决这个问题: npm i -g nrm@1.0.1