|
|
| (未显示同一用户的22个中间版本) |
| 第1行: |
第1行: |
| == 引言 ==
| |
| == 目录 ==
| |
|
| |
|
| * [[/依赖检查|依赖检查]]
| | # [[/依赖检查|依赖检查]] |
| * [[/规范|规范]]
| | # [[/规范|规范]] |
| * [[/代理|代理]]
| | # [[/代理|代理]] |
| * [[/源|源]]
| | # [[/源|源]] |
| * [[/配置文件|配置文件]]
| | # [[/配置文件|配置文件]] |
| * [[/缓存|缓存]]
| | # [[/版本号码|版本号码]] |
| * [[/域|域]]
| | # [[/package.json|package.json]] |
| * [[/环境变量|环境变量]]
| | # [[/缓存|缓存]] |
| * [[/指令|指令]]
| | # [[/域|域]] |
| * [[/权限|权限]]
| | # [[/环境变量|环境变量]] |
| | | # [[/指令|指令]] |
| == 全局 ==
| | # [[/权限|权限]] |
| === 查看 ===
| | # [[/工具|工具]] |
| {{shc_out|<syntaxhighlight lang="bash">
| | # [[/error|error]] |
| npm ls -g --depth=0</syntaxhighlight>|<syntaxhighlight lang="text">
| | # [[/别名|别名]] |
| /usr/local/lib
| | # [[/token|Token]] |
| ├── @vue/cli@4.4.6
| |
| ├── n@6.5.1
| |
| ├── nodemon@2.0.4
| |
| ├── npm@6.14.5
| |
| ├── npm-check@5.9.2
| |
| ├── nrm@1.2.1
| |
| ├── webpack@4.43.0
| |
| └── yarn@1.22.4</syntaxhighlight>|$}}
| |
| === 更新 ===
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| npm i npm -g</syntaxhighlight>|$|/home/kangkk}}
| |
| === 权限 ===
| |
| 如果直接全局安装会报错。
| |
| {{shc_out|<syntaxhighlight lang="bash">
| |
| npm install webpack-cli -g
| |
| </syntaxhighlight>|<syntaxhighlight lang="text">
| |
| npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
| |
| npm WARN webpack-cli@3.3.12 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.
| |
| | |
| npm ERR! code EACCES
| |
| npm ERR! syscall access
| |
| npm ERR! path /usr/local/lib/node_modules
| |
| npm ERR! errno -13
| |
| npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
| |
| npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
| |
| npm ERR! errno: -13,
| |
| npm ERR! code: 'EACCES',
| |
| npm ERR! syscall: 'access',
| |
| npm ERR! path: '/usr/local/lib/node_modules'
| |
| npm ERR! }
| |
| npm ERR!
| |
| npm ERR! The operation was rejected by your operating system.
| |
| npm ERR! It is likely you do not have the permissions to access this file as the current user
| |
| npm ERR!
| |
| npm ERR! If you believe this might be a permissions issue, please double-check the
| |
| npm ERR! permissions of the file and its containing directories, or try running
| |
| npm ERR! the command again as root/Administrator.
| |
| | |
| npm ERR! A complete log of this run can be found in:
| |
| npm ERR! /home/kangjian/.npm/_logs/2020-06-27T12_46_35_227Z-debug.log
| |
| </syntaxhighlight>|$}}
| |
| | |
| 安装目录添加权限
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| sudo chown -R ${USER} /usr/local/lib/node_modules/
| |
| sudo chown -R ${USER} /usr/local/bin/</syntaxhighlight>|kangjian@kangkk:/usr/local/lib$}}
| |
| | |
| == 指令 ==
| |
| | |
| == 全局 ==
| |
| === 普通用户 ===
| |
| 在 Linux 和 Mac 中,普通用户如何全局安装 npm 包:<br>
| |
| 需要将 npm 包存放在当前用户的主目录 <code>.npm-packages</code> 中
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| mkdir .npm-packages</syntaxhighlight>|kangkk@LAPTOP-S5B1JMCV:~$}}
| |
| | |
| {{hc|~/.npmrc|<syntaxhighlight lang="javascript">
| |
| prefix=${HOME}/.npm-packages</syntaxhighlight>}}
| |
| {{hc|.bashrc or .bash_profile or .zshrc | <syntaxhighlight lang="bash">
| |
| # 定义npm存放的目录 | |
| NPM_PACKAGES="${HOME}/.npm-packages"
| |
| | |
| # 确保node可以找到安装的包
| |
| NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
| |
| | |
| # 确保可以使用安装的二进制应用和man文档
| |
| PATH="$NPM_PACKAGES/bin:$PATH"
| |
| # Unset manpath so we can inherit from /etc/manpath via the `manpath`
| |
| # command
| |
| unset MANPATH # delete if you already modified MANPATH elsewhere in your config
| |
| MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
| |
| </syntaxhighlight>}}
| |
| | |
| == 参数 ==
| |
| {| class="wikitable"
| |
| |-
| |
| | [[/unsafe-perm|unsafe-perm]] || postinstall || 示例
| |
| |-
| |
| | 示例 || 示例 || 示例
| |
| |-
| |
| | 示例 || 示例 || 示例
| |
| |}
| |
| === legacy-peer-deps ===
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| npm i --legacy-peer-deps</syntaxhighlight>|$|/home/kangkk}}
| |
| | |
| == view ==
| |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| npm view think-view versions</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| [
| |
| '1.0.0', '1.0.1',
| |
| '1.0.2', '1.0.3',
| |
| '1.0.4', '1.0.5',
| |
| '1.0.7', '1.0.8',
| |
| '1.0.9', '1.0.10',
| |
| '1.0.11', '1.0.12',
| |
| '1.0.13'
| |
| ] | |
| </syntaxhighlight>|$|/home/kangkk}}
| |
| | |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| npm view think-view versions --json</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| [
| |
| "1.0.0",
| |
| "1.0.1",
| |
| "1.0.2",
| |
| "1.0.3",
| |
| "1.0.4",
| |
| "1.0.5",
| |
| "1.0.7",
| |
| "1.0.8",
| |
| "1.0.9",
| |
| "1.0.10",
| |
| "1.0.11",
| |
| "1.0.12",
| |
| "1.0.13"
| |
| ] | |
| </syntaxhighlight>|$|/home/kangkk}}
| |
| | |
| {{Shc_out|<syntaxhighlight lang="bash">
| |
| npm view think-view@1.0.13 engines</syntaxhighlight>|<syntaxhighlight lang="bash">
| |
| { node: '>=6.0.0' }
| |
| </syntaxhighlight>|$|/home/kangkk}}
| |
| | |
| == package-lock ==
| |
| 禁止生成 package-lock.json 文件。
| |
| {{shc|<syntaxhighlight lang="bash">
| |
| npm config set package-lock false</syntaxhighlight>|$|/home/kangkk}}
| |
| == other ==
| |
| 设置 python 环境的指向。
| |
| | |
| <syntaxhighlight lang="bash">
| |
| npm config set python "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
| |
| </syntaxhighlight>
| |
| | |
| == 分析工具 ==
| |
| # [https://github.com/privatenumber/pkg-size.dev pkg-size.dev] | |
| # [https://github.com/pastelsky/bundlephobia bundlephobia.com]
| |
| == error ==
| |
| * rollbackFailedOptional
| |
| *: {{shc|<syntaxhighlight lang="bash">
| |
| git config --global http.proxy http://127.0.0.1:1080
| |
| git config --global https.proxy https://127.0.0.1:1080
| |
| npm i
| |
| git config --global --unset http.proxy
| |
| git config --global --unset https.proxy</syntaxhighlight>|$}}
| |
| * permission denied, mkdir '/usr/local/lib/node_modules/node-sass/.node-gyp'
| |
| *: {{shc|<syntaxhighlight lang="bash">
| |
| sudo npm install node-sass --unsafe-perm --save-dev</syntaxhighlight>|$}}
| |
| * Error: ENOSPC: System limit for number of file watchers reached
| |
| *: 文件监视程序的系统产生了限制,达到了默认上限。
| |
| {{shc_out|<syntaxhighlight lang="bash">
| |
| cat /proc/sys/fs/inotify/max_user_watches
| |
| </syntaxhighlight>|<syntaxhighlight lang="javascript">
| |
| 8192
| |
| </syntaxhighlight>|$}}
| |
| *: 临时增加文件监听限制
| |
| *: {{shc|<syntaxhighlight lang="bash">
| |
| sudo sysctl fs.inotify.max_user_watches=524288</syntaxhighlight>|$}}
| |
| *: 永久增加
| |
| *: {{shc|<syntaxhighlight lang="bash">
| |
| echo fs.inotify.max_user_watches = 524288 | sudo tee -a /etc/sysctl.conf
| |
| sudo sysctl -p</syntaxhighlight>|$}}
| |
| * Node Sass could not find a binding for your current environment
| |
| *: 重新添加 sass 依赖
| |
| *: {{shc|<syntaxhighlight lang="bash">
| |
| npm rebuild node-sass</syntaxhighlight>|$}}
| |
| * Error: EACCES: permission denied, mkdir '/opt/nodejs/node-v12.18.2-linux-x64/lib/node_modules/node-sass/.node-gyp'
| |
| *: <syntaxhighlight lang="bash">
| |
| sudo npm install node-sass --unsafe-perm --save-dev</syntaxhighlight>
| |
| * This is probably not a problem with npm. There is likely additional logging
| |
| * Error: connect ETIMEDOUT 104.20.23.46:443 gyp ERR! stack at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
| |
| *: <syntaxhighlight lang="bash">
| |
| rm -rf ~/.node-gyp</syntaxhighlight>
| |
| * wsl, Error: EACCES: permission denied, rename
| |
| : {{shc|<syntaxhighlight lang="bash">
| |
| npm config set unsafe-perm=true
| |
| npm config set prefix="/mnt/d/npm-global"</syntaxhighlight>|$|/home/kangkk}}
| |
| * ERESOLVE unable to resolve dependency tree
| |
| : node版本太高了
| |