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 使用问题汇总 #565

Open
oxUnd opened this issue Jun 25, 2015 · 124 comments
Open

NPM 使用问题汇总 #565

oxUnd opened this issue Jun 25, 2015 · 124 comments
Labels

Comments

@oxUnd
Copy link
Contributor

oxUnd commented Jun 25, 2015

现在 NPM 可谓是 node 的最佳包管理平台,很自然的 FIS 也放在上面。但是大家对 NPM 不甚了解,碰到一些稀奇古怪的安装问题觉着很摸不着头脑,然后把怒气直指 FIS。为了大家不动肝火,以及方便大家查阅,打算对常 NPM 常见问题在此汇总一下。

如何查看所有 NPM 的设置

npm config ls -l

全局安装了无法找到命令

大家都知道,FIS 是要求全局安装的,是因为避免由于 FIS 多版本不同项目目录下而导致编译时有差异,而导致不必要的麻烦。

有些同学可能遇到了

npm install -g fis

命令行执行 fis找不到这个命令。这时候一般都开始抓瞎了。

解决办法:

  • 执行 npm prefix -g 会输出全局安装路径
  • Windows 用户把输出的路径添加到环境变量 %PATH% 里面,环境变量的设置请参考 百度
  • 类 Unix 用户把 $(npm prefix -g)/bin 目录设置到 PATH 中。
    • 用 bash echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc && source ~/.bashrc
    • 用 zsh echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.zshrc && source ~/.zshrc

全局安装了无法 require 这个包

解决办法:

设置环境变量

  • Windows

    NODE_PATH=<prefix>/node_modules
    
    • <prefix> 执行 npm prefix -g 获得
  • 类 Unix

    export NODE_PATH=$(npm prefix -g)/lib/node_modules

安装过程中报错,checksum 失败

出现类似这样的错误

gyp ERR! stack Error: node-v0.12.7.tar.gz local checksum 
a797be06553ea8e13a6ec9c3cdd8ed1b065dd1d05d2a3a0378296e70cf16d5ab not match remote
b23d64df051c9c969b0c583f802d5d71de342e53067127a5061415be7e12f39d

解决办法

清除缓存再进行安装

npm cache clean

安装过程中说没权限,sudo 也不行

一般发生在_类Unix_系统中

  • 获取缓存目录 npm config get cache (~/.npm)

  • 删除缓存目录

    sudo rm -rf ~/.npm
  • 再次安装坚决不要用 sudo,如果还是出现权限问题请修改安装路径权限

安装长时间不成功

NPM 平台无奈被祖国电子长城防火墙阻隔了,时不时抽风。如果遇到这种情况只有三种解决办法;

  • 一次次重试

  • 换个国内的源

    npm install -g fis --disturl=http://registry.npm.taobao.org/mirrors/node --registry=http://registry.npm.taobao.org
    
  • 添加代理

    npm config set proxy <http proxy>
    npm config set https-proxy <https proxy> 
    
    • <http proxy> 换成你自己的 http 代理地址
    • <https proxy> 换成你自己的 https 代理地址

    注意: 如果换代理了,请更改配置,不然你又会怀疑上帝

安装报 gyp* 编译不成功

得详细说一下为啥有这种错误,其实 node 里面不是跑得是 V8 么,那么其第三方扩展机制也全盘拿了过来。这块说的第三方扩展是指 addon 插件,也就是所谓的 native 插件。请不要被这个词语吓着了,说白了就是写一个二进制插件,用 c++ 写的。

所以这类插件需要编译器(gcc,clang,vs)编译,安装这类插件的时候如果你系统没有装 VS 或者是 gcc 什么的编译器就会报错。

而且这类插件在各个版本的 node 下兼容性不好,所以报编译语法错误也是很正常的。遇到此类错误只有两种解决办法;

  • 自己搞懂机制自己编译插件
  • 到作者 GitHub 上求助

想本地安装而非全局安装,运行 FIS 怎么搞

由于种种维护上的原因,FIS 必须要全局安装包括其插件,有些人就受不了这个,觉着是反模式,咋眼一看确实是,但长远来看安装全局同一版本才是王道,有过 node 工程实践的同学对此估计深有体会。

但不巧,上线编译的时候用的编译机不是自己的机器,而无法部署 FIS 编译环境啊。这时候怎么办呢?

首先,我们得了解一下 NPM 安装的时候的一些处理。不才,直接贴 NPM 的文档。

DIRECTORIES
       See npm help 5 npm-folders to learn about where npm puts stuff.

       In particular, npm has two modes of operation:

       - global mode:
         npm installs packages into the install prefix at prefix/lib/node_modules and bins are installed in prefix/bin.

       - local mode:
         npm installs packages into the current project directory, which defaults to  the  current  working  directory.   Packages  are
         installed to ./node_modules, and bins are installed to ./node_modules/.bin.


       Local mode is the default.  Use --global or -g on any command to operate in global mode instead.

看到 local mode 的解释了吧。当 local mode 安装的时候,会把 bin 链接到 ./node_modules/.bin 目录下。

那么当本地安装 FIS

npm install fis

执行

./node_modules/.bin/fis -v

来调用 FIS 进行操作。

假设你想进行更方便的操作,设置两个环境变量即可。

  • PATH 执行命令靠它
  • NODE_PATH node require 靠它

然后就没有然后了,你可以肆意蹂躏了。

@oxUnd oxUnd added the faq label Jun 25, 2015
@oxUnd oxUnd changed the title NPM 使用注意事项 NPM 使用问题汇总 Jun 25, 2015
@boboxiao
Copy link

boboxiao commented Aug 4, 2015

始终还是安装不成功!

@boboxiao
Copy link

boboxiao commented Aug 4, 2015

报错:
npm ERR! Error: shasum check failed for /tmp/npm-32475-sRV7oL_x/registry.npmjs.org/node-pngcrush/-/node-pngcrush-0.2.0.tgz
npm ERR! Expected: bd87b2ad24938604ae888add94ae58fa111354c8
npm ERR! Actual: 8d663ed6b7329fbd55ac60dd1b8beae4d5d1dffd
npm ERR! From: https://registry.npmjs.org/node-pngcrush/-/node-pngcrush-0.2.0.tgz
npm ERR! at /usr/local/lib/node_modules/npm/node_modules/sha/index.js:38:8
npm ERR! at ReadStream. (/usr/local/lib/node_modules/npm/node_modules/sha/index.js:85:7)
npm ERR! at ReadStream.emit (events.js:117:20)
npm ERR! at _stream_readable.js:938:16
npm ERR! at process._tickCallback (node.js:419:13)
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/npm/npm/issues

npm ERR! System Darwin 14.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "fis3"
npm ERR! cwd /Users/bobo
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/bobo/npm-debug.log
npm ERR! not ok code 0

@lengziyu
Copy link

lengziyu commented Aug 7, 2015

我和楼上一样,安装不成功!

@oxUnd
Copy link
Contributor Author

oxUnd commented Aug 7, 2015

npm cache clean

后重试

@lengziyu
Copy link

lengziyu commented Aug 7, 2015

还是报错- -
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "F:\node\node.exe" "F:\node\node_modules\npm\bin\npm-cli.
js" "install" "-g" "fis3"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! syscall getaddrinfo

npm ERR! network getaddrinfo ENOTFOUND registry.npmjs.org
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settin
gs.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Administrator\npm-debug.log

@oxUnd
Copy link
Contributor Author

oxUnd commented Aug 7, 2015

@lengziyu 你网络不通?为什么连 npm 都访问不了?

@lengziyu
Copy link

lengziyu commented Aug 7, 2015

@xiangshouding 额,可能是我网络问题,最近总是断线。我回家试试看,谢谢~

@lengziyu
Copy link

lengziyu commented Aug 7, 2015

@xiangshouding 网络恢复了,安装成功了,再次感谢~慢慢开始撸FIS了

@AkkaXdXd
Copy link

AkkaXdXd commented Aug 7, 2015

fis-command-server@0.7.6 这个依赖找不到啊 什么情况啊

@AkkaXdXd
Copy link

AkkaXdXd commented Aug 7, 2015

npm WARN install Couldn't install optional dependency: No compatible version fou
nd: fis-command-server@0.7.6
npm WARN install Valid install targets:
npm WARN install ["0.7.5","0.7.4","0.7.3","0.7.2","0.7.1","0.7.0","0.7.0-beta6",
"0.7.0-beta5","0.7.0-beta4","0.7.0-beta3","0.7.0-beta2","0.7.0-beta","0.6.12","0
.6.11","0.6.10","0.6.9","0.6.8","0.6.7","0.6.6","0.6.5","0.6.4","0.6.3","0.6.2",
"0.6.1","0.6.0","0.5.9","0.5.8","0.5.7","0.5.6","0.5.5","0.5.4","0.5.3","0.5.2",
"0.5.1","0.5.0","0.4.9","0.4.8","0.4.7","0.4.6","0.4.5","0.4.4","0.4.3","0.4.2",
"0.4.1","0.4.0","0.3.4","0.3.3","0.3.2","0.3.1","0.3.0","0.2.8","0.2.7","0.2.6",
"0.2.5","0.2.4","0.2.3","0.2.2","0.2.1","0.2.0","0.1.9","0.1.8","0.1.7","0.1.6",
"0.1.5","0.1.3","0.1.2","0.1.1","0.1.0","0.0.8","0.0.7","0.0.6","0.0.4","0.0.3",
"0.0.2","0.0.1"]

@zhangtao07
Copy link
Member

0.7.6 今天几小时前刚发布,可能是你的npm源还没更新,请稍后重试或者使用官方源试试

@AkkaXdXd
Copy link

AkkaXdXd commented Aug 7, 2015

fis3 如果css 不是相对路径的 有没有办法 修改 rel="stylesheet" type="text/css" href="<%=path%>/css/base.css"> 中的base.css 为 base_c9fff2a.css

@oliverxyy
Copy link

我安装好了,但是过程中出现了这个warning:npm WARN optional dep failed, continuing fsevents@0.3.8,这是神马问题撒?

@AkkaXdXd
Copy link

@oliverxyy npm cache clean 试试

@MurphyZL
Copy link

安装不成功:
fix@1.9.29 uninstall C:\User\zhangling\AppData\Roaming\npm\node_modules\fis
node -e "var cp = require('child_process'); cp.exec('bin/fis server stop');"

@MurphyZL
Copy link

安装fis3运行安装程序之后:

images@2.1.5 install C:\Users\zhangling\AppData\Roaming\npm\node_modules\fis3\node_modules\fis-spriter-csssprites\node_modules\images
echo "Hello, Word."

@liuhanyu200
Copy link

同上 输出 hello world 同上 源有问题 同上 输出warning:npm WARN optional dep failed, continuing fsevents@0.3.8

@liuhanyu200
Copy link

现在 还在加载 估计要失败

@ordheart
Copy link

ordheart commented Sep 1, 2015

fis3 有米有国内资源地址,装不上哎,跪求

@2413052180
Copy link

装上了,但运行fis3 -v的时候说找不到,环境变量加弄了,怎么回事啊

@shenfusheng
Copy link

安装完fis3,运行fis3 -v 时就会报错如下:
sh.exe": /c/Users/fusheng/AppData/Roaming/npm/fis3: No such file or directory

@oxUnd
Copy link
Contributor Author

oxUnd commented Sep 9, 2015

@shenfusheng 请在 CMD 中执行,而不是 git-bash 亦或是 cygwin console

@shenfusheng
Copy link

@xiangshouding 重新再git-bash执行几次就ok了,有个疑问就是为什么一定要在CMD中执行呢?

@liang511
Copy link

@zzlsan30 请问fis3 release的时候出现cannot find module 'isarray'这个问题你有解决了吗,我也是把文件拷到内网,执行fis3 -v成功

@oxUnd
Copy link
Contributor Author

oxUnd commented Mar 9, 2017

@liang511 没有 copy 全?或者来点更多错误信息

@liang511
Copy link

liang511 commented Mar 9, 2017

@xiangshouding 应该是当时没copy全吧,后来同事重新弄了一份就可以了

@Mr-funny
Copy link

Mr-funny commented Jun 3, 2017

C:\Users\FOX\Desktop\vue饿了么实战\seller\build\dev-server.js:36
errno: 0;
^
SyntaxError: Unexpected token ;
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
at startup (bootstrap_node.js:150:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! seller@1.0.0 dev: node build/dev-server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the seller@1.0.0 dev script 'node build/dev-server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the seller package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build/dev-server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs seller
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls seller
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\FOX\AppData\Roaming\npm-cache_logs\2017-06-03T00_56_29_81 5Z-debug.log
有大神帮我解决一下这个是什么错误吗??我新手

@oxUnd
Copy link
Contributor Author

oxUnd commented Jun 3, 2017 via email

@oxUnd oxUnd mentioned this issue Jul 15, 2017
@a526672351
Copy link

为什么fis3本地安装必须./node_modules/.bin/fis3 才能运行,我看egg.js 的本地安装,egg-bin都不用cd进去/node_modules/.bin运行,这是啥原因?

@github-zhang
Copy link

github-zhang commented Jul 21, 2017

fis3 安装,不能用git-hash,只能用CMD

@pigpigever
Copy link

你好,我在linux下使用npm全局安装失败,代码诸如:

npm install express -g //或
npm install hexo-cli -g

在这之前我是使用源代码来安装nodejs的,有人知道是怎么回事吗

@oxUnd
Copy link
Contributor Author

oxUnd commented Sep 7, 2017

没权限 @pigpigever

@zhengyixin
Copy link

安装的时候报错

const Hoek = require('hoek');
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/usr/local/lib/node_modules/fis3/node_modules/fis-optimizer-png-compressor/node_modules/node-pngquant-native/node_modules/request/node_modules/hawk/lib/index.js:5:33)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
npm ERR! Darwin 16.7.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "fis3"
npm ERR! node v0.12.13
npm ERR! npm v2.15.0
npm ERR! code ELIFECYCLE

@oxUnd
Copy link
Contributor Author

oxUnd commented Nov 13, 2017

@zhengyixin

可以参考 Release https://github.com/fex-team/fis3/releases/tag/3.4.38 信息,最新版本支持要求 node 版本 4.x 以上。如果是低于这个版本的,可以安装久版本。

npm install -g fis3@3.4.36

@Domingowen
Copy link

Domingowen commented Feb 8, 2018

我遇到了这个问题,可以帮我解答一下吗??

就是 fis3 server start 直接报错
C:\Users\domingo.M1>fis3 server start

[INFO] Currently running fis3 (C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3)
fs.js:646
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EPERM: operation not permitted, open 'C:\Users\domingo.M1\AppData\Local.fis3-tmp\server\conf.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.writeFileSync (fs.js:1291:33)
at Function..write (C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3\lib\util.js:733:8)
at Object.
.serverInfo (C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3\node_modules\fis3-command-server\lib\util.js:79:32)
at start (C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3\node_modules\fis3-command-server\lib\server.js:20:8)
at C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3\node_modules\fis3-command-server\lib\server.js:139:21
at ChildProcess. (C:\Users\domingo.M1\AppData\Roaming\npm\node_modules\fis3\node_modules\fis3-command-server\lib\server.js:75:5)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

screenshot_1

谢谢你了

@baiqb
Copy link

baiqb commented Feb 8, 2018 via email

@Domingowen
Copy link

@baiqb 我试过了,不行,还是出现这个问题,然后又重新安装node,重新安装了其他的东西,也不行,直接懵逼了

@WangJia-mm
Copy link

ERR! code 1
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b 4.0 git://github.com/gulpjs/gulp.git /Users/wangjia16/.npm/_cacache/tmp/git-clone-84cd56a0
npm ERR! /Users/wangjia16/.npm/_cacache/tmp/git-clone-84cd56a0/.git: Permission denied
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/wangjia16/.npm/_logs/2018-05-23T13_45_44_405Z-debug.log

@oxUnd
Copy link
Contributor Author

oxUnd commented May 29, 2018

@WangJia-mm
/Users/wangjia16/.npm/_cacache/tmp/git-clone-84cd56a0/.git: Permission denied

不是说没权限么,可以把 .npm 目录直接删掉,在来一遍。

@carolcoral
Copy link

carolcoral commented Jul 30, 2018

自己基于jquery封装了一个js脚本,类似jquery使用$一样调用的,在vue项目中使用
import lcript from './lcript'
引入了该脚本,调用里面的方法
lcript.alert('.test')
然后就会一直提示

_lcript2.default.alert is not a function

请问怎么解决?!

封装的脚本地址:https://github.com/carolcoral/Lcript/tree/master/src/js

Have done!

change 'lcript' to 'window.lcript'

@niutd777
Copy link

niutd777 commented Sep 6, 2018

image
安装成功了 还是报错

@oxUnd
Copy link
Contributor Author

oxUnd commented Sep 11, 2018

@dyoner1 你这个 case 没有遇到过啊

@carolcoral
Copy link

@dyoner1 要不是路径问题,要不就死没有这个包,你去安装下或者是修改路径为绝对路径

@mryiyangzhang
Copy link

1550508722 1
报错信息是这样的,一直安装不成功请问怎么处理,minimatch版本实际是3.10.10.

@oxUnd
Copy link
Contributor Author

oxUnd commented Feb 18, 2019 via email

@mryiyangzhang
Copy link

可以加个qq嘛,824720459

@BoneDragons
Copy link

老哥老哥,这边我用 vue 项目,我的用户名是中文,当我 run 的时候
Error: Cannot find module 'C:\Users\乱码\AppData\Local\Temp\debugConnector.191.6707.61.js'
中文变成了乱码,如何解决,拜托了

@oxUnd
Copy link
Contributor Author

oxUnd commented May 17, 2019

@BoneDragons Windows 用户名虽然你用了中文,但貌似是用拼音建的文件夹,我看我 Windows 10 上就是这么。你具体仔细查验一下。

@SiriusYJN
Copy link

image
image
image
image
image
请问这是什么原因呢?

@zzhy1152767335
Copy link

请问全局安装的fis,报错unable to load plugin [fis-postprocessor-requirejs],要怎么进行环境配置啊?

@oxUnd
Copy link
Contributor Author

oxUnd commented Jun 21, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests