安装npm,nodejs - 使用laravel gulp

时间:2016-05-06 09:38:25

标签: linux node.js laravel npm gulp

我正在使用Linux。我试图使用Laravel 5.2来使用gulp。我安装了类似的节点:

sudo apt-get install nodejs

我还安装了npm:

sudo apt-get install npm

我有两个版本的最新版本。但它不会在我的项目的根目录中创建文件夹node_modules。 我已将它们联系起来 - 我已经尝试检查:

sudo ln -s /usr/bin/nodejs /usr/bin/node ln: failed to create symbolic link ‘/usr/bin/node’: File exists

我的packaage.json文件是:



{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "laravel-elixir": "^5.0.0",
    "bootstrap-sass": "^3.0.0"
  }
}




Gulpfile.js是:



var elixir = require('laravel-elixir');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    mix.sass('app.scss');
});




我的/resources/assets/css/app.scss文件是:



 @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

.container {
	color: purple;
}
h1 {
	color:green;
}
body {
	background-color: red;
	font-size:10px;
}




在我的编辑器中有错误: Can't resolve import into sass/scss file。 因为我没有文件夹node_modules

如何做到这一点?我做错了什么?当我跑gulp

谢谢!

编辑:当我安装npm时:



sudo apt-get install npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
npm is already the newest version.
The following packages were automatically installed and are no longer required:
  ant ant-optional antlr3 aspectj bsh javahelp2 junit junit-doc junit4
  junit4-doc libantlr-java libasm3-java libaspectj-java libbeansbinding-java
  libbetter-appframework-java libbindex-java libbsh-java libbytelist-java
  libcglib-java libcommons-codec-java libcommons-net1-java libeasymock-java
  libfelix-framework-java libfelix-main-java libflute-java libfreemarker-java
  libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libhamcrest-java
  libini4j-java libjcodings-java libjemmy2-java libjetty-java libjline-java
  libjna-java libjoda-time-java libjsch-java libjvyamlb-java libjzlib-java
  liblucene2-java libnb-absolutelayout-java libnb-apisupport3-java
  libnb-ide14-java libnb-java5-java libnb-javaparser-java
  libnb-org-openide-modules-java libnb-org-openide-util-java
  libnb-org-openide-util-lookup-java libnb-platform-devel-java
  libnb-platform13-java libnetx-java liboro-java libosgi-compendium-java
  libosgi-core-java libosgi-foundation-ee-java libsac-java
  libsequence-library-java libserf-1-1 libservlet2.5-java
  libsimple-validation-java libslf4j-java libsqljet-java
  libstringtemplate-java libsvn-java libsvn1 libsvnclientadapter-java
  libsvnkit-java libswing-layout-java libswingx1-java libtrilead-ssh2-java
  libxerces2-java libxml-commons-external-java libxml-commons-resolver1.1-java
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 55 not upgraded.




当我安装npm时:



sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nodejs is already the newest version.
nodejs set to manually installed.
The following packages were automatically installed and are no longer required:
  ant ant-optional antlr3 aspectj bsh javahelp2 junit junit-doc junit4
  junit4-doc libantlr-java libasm3-java libaspectj-java libbeansbinding-java
  libbetter-appframework-java libbindex-java libbsh-java libbytelist-java
  libcglib-java libcommons-codec-java libcommons-net1-java libeasymock-java
  libfelix-framework-java libfelix-main-java libflute-java libfreemarker-java
  libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libhamcrest-java
  libini4j-java libjcodings-java libjemmy2-java libjetty-java libjline-java
  libjna-java libjoda-time-java libjsch-java libjvyamlb-java libjzlib-java
  liblucene2-java libnb-absolutelayout-java libnb-apisupport3-java
  libnb-ide14-java libnb-java5-java libnb-javaparser-java
  libnb-org-openide-modules-java libnb-org-openide-util-java
  libnb-org-openide-util-lookup-java libnb-platform-devel-java
  libnb-platform13-java libnetx-java liboro-java libosgi-compendium-java
  libosgi-core-java libosgi-foundation-ee-java libsac-java
  libsequence-library-java libserf-1-1 libservlet2.5-java
  libsimple-validation-java libslf4j-java libsqljet-java
  libstringtemplate-java libsvn-java libsvn1 libsvnclientadapter-java
  libsvnkit-java libswing-layout-java libswingx1-java libtrilead-ssh2-java
  libxerces2-java libxml-commons-external-java libxml-commons-resolver1.1-java
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 55 not upgraded.




1 个答案:

答案 0 :(得分:1)

听起来你没有在项目目录中运行npm install。这样做会在项目目录中创建node-modules目录。

像mattferderer在评论中建议的那样,只是不做sudo,因为它会安装带有sudo权限的软件包,我不认为你会想要这样做。 ;)

Laravel会更喜欢本地版本的gulp(如果您还安装了全局版本)。只是让你知道bin将隐藏在$your_project_path/node_modules/.bin/gulp中。再次确保从存在gulpfile.js的项目目录中运行它。

如果仍然无法工作,我建议删除并清除nodejs并按照官方网站上的说明重新安装(有时简单sudo apt-get install nodejs npm并且链接无法工作):{{ 3}}