Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm link无效 #78

Closed
AprilLemon opened this issue Apr 22, 2024 · 4 comments
Closed

npm link无效 #78

AprilLemon opened this issue Apr 22, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@AprilLemon
Copy link

AprilLemon commented Apr 22, 2024

自己写了一个脚手架test-cli,用npm link到全局,npm ls -g 中存在test-cli,但是执行test-cli无效,无法将“test-cli”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再
试一次。。另外一台电脑直接安装官方node版本包,测试结果是正常的。

@1111mp
Copy link
Owner

1111mp commented Apr 22, 2024

我自己在本地试了一下,是可以正常工作的。

工作目录:

|-- linker
    |-- package.json
    |-- index.mjs
|-- project
    |-- index.mjs

image

linker/*:

// package.json
{
  "name": "linker",
  "version": "1.0.0",
  "description": "npm link test",
  "main": "index.mjs",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {}
}

// index.mjs
export function add(a, b) {
  return a + b;
}

project/index.mjs:

import { add } from 'linker';

const ret = add(1, 2);

console.log(ret);
  • "linker/" 目录下执行 npm link
  • "project/" 目录下执行 npm link linker
  • "project/" 目录下执行 node index.mjs

结果如下:

image

请问你在link之后切换了node的版本吗,因为nvm-desktop在设计的时候是保持每个node版本之间相互隔离的,所以如果中间切换了版本,请重新link一下。

@AprilLemon
Copy link
Author

我自己在本地试了一下,是可以正常工作的。

工作目录:

|-- linker
    |-- package.json
    |-- index.mjs
|-- project
    |-- index.mjs

image

linker/*:

// package.json
{
  "name": "linker",
  "version": "1.0.0",
  "description": "npm link test",
  "main": "index.mjs",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {}
}

// index.mjs
export function add(a, b) {
  return a + b;
}

project/index.mjs:

import { add } from 'linker';

const ret = add(1, 2);

console.log(ret);
  • "linker/" 目录下执行 npm link
  • "project/" 目录下执行 npm link linker
  • "project/" 目录下执行 node index.mjs

结果如下:

image

请问你在link之后切换了node的版本吗,因为nvm-desktop在设计的时候是保持每个node版本之间相互隔离的,所以如果中间切换了版本,请重新link一下。

感谢,已解决,当前项目选用版本后,需要将该版本放入系统path中。

@1111mp
Copy link
Owner

1111mp commented Apr 23, 2024

感谢你的回复,不过经过本地测试这确实是一个bug。

在执行npm link添加全局包的时候确实需要跟踪并添加一个shim%HOMEPATH%\.nvmd\bin\目录下,这个我后续支持一下,得先学习一下npm link/unlink命令的文档。

我先把这个issue重启开启,后续支持npm link/unlink的命令之后再关闭,请知悉。

@1111mp
Copy link
Owner

1111mp commented May 8, 2024

目前在最新的 Release v3.3.0 中已经修复了这个问题,支持 npm 的 link & unlink & update 命令

那么我就先将此 issue 关闭了,当然后续如果有任何问题都可以随时重新开启,谢谢 🌹

@1111mp 1111mp closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants