Gulp - 找不到模块'gulp-rename' [英] Gulp - Cannot find module 'gulp-rename'

查看:971
本文介绍了Gulp - 找不到模块'gulp-rename'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试设置Gulp来编译SCSS文件,并在此过程中重命名SCSS文件 - 例如:



我想 SCSS / original.scss 保存为 CSS / new.css



这是在Windows 10虚拟机上



我已经安装了Gulp,安装了gulp-sass,它们都工作得很好

  var gulp = require('gulp'); 
var sass = require('gulp-sass');
$ b $ gulp.task('compile-new-main',function(){
return gulp.src('scss / new-main.scss')
.pipe sass())//使用gulp-sass
.pipe(gulp.dest('css'))
});

运行上面的gulp任务很好,但是当我尝试安装gulp-rename时,任务中断:

  var gulp = require('gulp'); 
var sass = require('gulp-sass');
var rename = require(gulp-rename);
$ b $ gulp.task('compile-new-main',function(){
return gulp.src('scss / new-main.scss')
.pipe sass())//使用gulp-sass
.pipe(rename(styles.css))
.pipe(gulp.dest('css'))
});

我最初尝试使用此命令安装gulp rename

  npm install gulp-rename 

我曾经为gulp-sass工作过,看起来像以前一样工作得很好,显然不是,但我不知道如何或为什么。



我做了一些Google搜索并尝试过在全球安装它似乎再次安装正常

  npm install gulp-rename -g 

我还看到了一些关于将gulp-rename保存为开发者依赖的建议,所以我尝试了

pre $
$ b $ p >再次没有安装错误。



当我尝试运行我的gulp任务时,这是我得到的错误消息:


错误:无法在Function.Module._resolveFilename(module.js:469:15)处找到模块'gulp-rename'

at Function.Module._load module.js:417:25 )
在Module.require(module.js:497:17)
在require(internal / module.js:20:19)
在Object。 (C:\Projects\VAT-Expert\gulpfile.js:3:14)
在Module._compile(module.js:570:32)
在Object.Module._extensions ..在module.load(module.js:487:32)处
在tryModuleLoad(module.js:446:12)处
$ b $在Function.Module ._load(module.js:438:3)

我无法理解我在这里做错了什么,想想我已经在这里添加了所有的相关信息 - 非常感谢任何指导或建议,我可以试试这个!



N

解决方案

首先,确保gulp-rename被列在 package.json 依赖关系 devDependencies 。然后运行:

  npm uninstall -g gulp 
npm install -g gulp
rm -rf node_modules
npm install

然后再次检查。


I trying to set up Gulp to compile a SCSS file and also rename the SCSS file in the process - so for example:

I want SCSS/original.scss to be saved as CSS/new.css

This is on a Windows 10 VM

I have installed Gulp, installed gulp-sass which all worked just fine

var gulp = require('gulp');
var sass = require('gulp-sass');

gulp.task('compile-new-main', function(){
 return gulp.src('scss/new-main.scss')
  .pipe(sass()) // Using gulp-sass
  .pipe(gulp.dest('css'))
 });

Running the above gulp task works just fine but when I try and install gulp-rename as the following the task breaks:

var gulp = require('gulp');
var sass = require('gulp-sass');
var rename = require("gulp-rename");

gulp.task('compile-new-main', function(){
 return gulp.src('scss/new-main.scss')
  .pipe(sass()) // Using gulp-sass
  .pipe(rename("styles.css"))
  .pipe(gulp.dest('css'))
 });

I initially tried just installing gulp rename with this command

npm install gulp-rename

The same as I did for gulp-sass which seemed to work just fine as before, clearly not but I'm not sure how or why.

I've done some Googling and tried installing it globally which again seemed to install fine

npm install gulp-rename -g

And I also saw some recommendations of saving gulp-rename as a dev-dependancy so I tried

npm install gulp-rename --save-dev

Again no errors in installing.

When I try and run my gulp task this is the error message I get:

Error: Cannot find module 'gulp-rename' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (C:\Projects\VAT-Expert\gulpfile.js:3:14) at Module._compile (module.js:570:32) 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)

I can't get my head around what I've done wrong here, think I've added all of the relevant information here - very much appreciate any guidance or advice on what I could try on this one!

N

解决方案

First, make sure that gulp-rename is listed in your package.json under dependencies or devDependencies. Then run:

npm uninstall -g gulp
npm install -g gulp
rm -rf node_modules
npm install 

Then check again.

这篇关于Gulp - 找不到模块'gulp-rename'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆