关于 Laravel 入门教程中 cnpm install 后终端报错的问题

细节如下:

file

file

file

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 16
Summer

第一步. 先卸载 cnpm

$ npm uninstall -g cnpm

第二步. 使用 aliascnpm

命令行下:

$ printf '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
  --cache=$HOME/.npm/.cache/cnpm \
  --disturl=https://npm.taobao.org/dist \
  --userconfig=$HOME/.cnpmrc"' >> ~/.bashrc && source ~/.bashrc

这时候再 cnpm -v ,应该是以下:

file

第三步 删除 node_modules

进入你的项目文件夹下,删除 node_modules 文件夹。

第四步 重新安装

在你的项目文件夹下,命令行:

$ cnpm install
7年前 评论

@Summer 咋不用yarn ,比 npm速度真的是快了太多

7年前 评论
Summer

@young 有这个打算

7年前 评论

我见到比较多的这个错误原因是因为虚拟机在 windows 文件系统下没有权限创建 symlink 文件,一个办法是添加 --no-bin-links 选项

文档 如果你是在 Windows 系统上或在 Windows 主机系统上运行 VM 进行开发,你需要在运行 npm install 命令时将 --no-bin-links 开启:

npm install --no-bin-links

添加了 --no-bin-links 貌似 npm 的一些命令只有 windows 版本的 .cmd 文件,linux 上运行会提示没有安装。。。

另外一个解决办法是修改 Vagrantfile,添加这个,然后运行 vagrant up 的那个命令行也要用管理员运行。

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    .
    .
    .
    config.vm.provider "virtualbox" do |v|
        v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    end
end
7年前 评论

@悠然见南山 先把 vagrant 停了 然后cmd右键管理员运行 再vagrant up 不行吗?

7年前 评论
lijinma

@Summer 看他的报错,他的 cnpm 应该也是用的 alias

7年前 评论
Summer

@Aufree 在更新 Windows 安装的课程,并且将会重新定制盒子,让你使用 yarn 并且是在有缓存的情况下安装。将会避免很多没必要的 debug,最快今天下午就能给出来,到时候通知你。

7年前 评论

@悠然见南山 最新的教程已 使用 Yarn 来替代 NPM 进行讲解,可以先运行下面命令来移除本机 Homestead:

cd ~/Homestead && vagrant halt && vagrant box remove laravel/homestead && vagrant destroy

再根据教程 安装使用 Homestead 来导入教程定制化过的 Homestead 包。

然后就可以在项目中直接使用下面命令来安装第三方扩展啦:

$ yarn install
7年前 评论

谢谢大家的帮忙,用yarn install解决了gulp watch和cnpm install问题,但是在yarn install 之前需要用@oustn 提供的方法在Vagrantfile当中添加一行命令,然后还得用管理员权限运行终端,如果不这样做 yarn install依旧会报错@Summer @Aufree

7年前 评论

@oustn 谢谢,问题解决了,你说得对要用管理员权限运行终端还得修改Vagrantfile

7年前 评论

@悠然见南山 @oustn 为什么我在Vagrantfile 添加命令 之后 vagrant up 报错。虚拟机起不来。

E:\Homestead>vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Clearing any previously set forwarded ports...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["modifyvm", "30f0f3bd-37a4-49a8-8008-164f213aafef", "--natpf1", "delet
e", "ssh", "--natpf1", "delete", "tcp33060", "--natpf1", "delete", "tcp44300", "
--natpf1", "delete", "tcp54320", "--natpf1", "delete", "tcp8000"]

Stderr: VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (ext
ended info not available)
VBoxManage.exe: error: Context: "LockMachine(a->session, LockType_Write)" at lin
e 507 of file VBoxManageModifyVM.cpp
7年前 评论

@方希 从报错信息来看,应该是之前运行的虚拟机没有停止,然后又用另外一个账号(管理员)账号启动虚拟机,导致的这个问题。解决办法:用之前运行的那个账号先停止 vagrant halt ,然后重新用管理员启动。

粗暴点的办法,重启之后直接用管理员启动vagrant.

7年前 评论

@oustn 感谢 可能是直接关了控制台造成的。没仔细看报错 ,确实是这个问题。

而且我发现 不知道 是不是因为 node-sass 升级了还是怎么回事。yarn install/npm insall 都出现了 node-sass 报错 提示 需要升级 node 版本。 我把 node 升级到 7.4.0 之后就好了。
我在不同的环境都出现了这个问题。

7年前 评论

@Aufree 在laravel 5.5 里面 yran 一样没有用!

6年前 评论

@Aufree 在编译 sass 的时候报错的

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!