0

我的安装可能搞砸了,我不知道。

前段时间我用 N 包管理器(脚本?包?)重新安装了节点来解决sudo我的全局包的问题,​​今天我遇到了一个问题——我不能在节点 REPL 中要求全局安装包(require('lodash')例如)。

我很确定我的节点设置搞砸了,但是我浏览网络的次数越多,我就越困惑——什么是、、、、、、哪些以及为什么已经过时$NODE_MODULES,有什么区别等等。$PREFIX.../lib/node.../lib/node_modules$N_PREFIX

我当前的设置如下所示:

# fragment of ~/.bashrc
# setup NODE
export N_PREFIX="$HOME/.n"
export PATH=$N_PREFIX/bin:$PATH

目录结构:

# output of `tree $N_PREFIX -L 2`. Arrows are symlinks, bin/node is executable
/home/tooster/.n
├── bin
│   ├── check -> ../lib/node_modules/checker/cli.js
│   ├── eslint -> ../lib/node_modules/eslint-cli/bin/eslint.js
│   ├── eslint-cli -> ../lib/node_modules/eslint-cli/bin/eslint.js
│   ├── ffmpeg-bar -> ../lib/node_modules/ffmpeg-progressbar-cli/lib/main.js
│   ├── js-yaml -> ../lib/node_modules/js-yaml/bin/js-yaml.js
│   ├── node
│   ├── npm -> ../lib/node_modules/npm/bin/npm-cli.js
│   ├── npx -> ../lib/node_modules/npm/bin/npx-cli.js
│   ├── tsc -> ../lib/node_modules/typescript/bin/tsc
│   └── tsserver -> ../lib/node_modules/typescript/bin/tsserver
├── include
│   └── node
├── lib
│   └── node_modules
├── n
│   └── versions
└── share
    ├── doc
    ├── man
    └── systemtap

以及从 Node REPL 返回的“模块”:

Module {
  id: '<repl>',
  path: '.',
  exports: {},
  filename: null,
  loaded: false,
  children: [],
  paths: [                              <-- None of these actually exist
    '/home/tooster/repl/node_modules',
    '/home/tooster/node_modules',
    '/home/node_modules',
    '/node_modules',
    '/home/tooster/.node_modules',
    '/home/tooster/.node_libraries,
    '/home/tooster/.n/lib/node'
  ]
}

我找不到有关.../lib/node和之间差异的任何信息.../lib/node_modules。将后者符号链接到前者似乎有效,但我不知道这样做的后果是什么,所以我宁愿不要盲目地这样做。

npm config get prefix返回/home/tooster/.n

使用 N 正确安装 npm 应该是什么样子?我想让我的全局安装包在 REPL 中可用,因为我经常在 Node.js 中编写快速脚本。

4

0 回答 0