错误:无法找到模块&gulp-uglify / minifier'

时间:2017-05-21 04:26:42

标签: node.js npm gulp

环境

Ubuntu 17.04

步骤

通过official instructions安装节点:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

通过official instructions安装gulp:

npm install --global gulp-cli

导致权限错误:

Error: EACCES: permission denied, access '/usr/lib/node_modules'

因此遵循相关的official instructions

# Make a directory for global installations:
mkdir ~/.npm-global

# Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'

# Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH

# Back on the command line, update your system variables:
source ~/.profile

在我的项目文件夹中使用以下内容创建了一个package.json文件:

{
  "devDependencies": {
  },
  "dependencies": {}
}

在我的项目文件夹中运行以下内容:

npm install gulp --save-dev
npm install gulp-clean-css --save-dev
npm install gulp-concat --save-dev
npm install gulp-rename --save-dev
npm install gulp-sass --save-dev
npm install gulp-uglify --save-dev
npm install pump --save-dev
npm install uglify-js-harmony --save-dev

然后填充package.json文件,使其看起来像:

{
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-clean-css": "^3.3.1",
    "gulp-concat": "^2.6.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-uglify": "^3.0.0",
    "pump": "^1.0.2",
    "uglify-js-harmony": "^2.7.7"
  },
  "dependencies": {}
}

然后:

npm install --global gulp-cli

gulpfile.js中的相关任务如下所示:

// BEGIN get gulp plugins
var gulp = require('gulp');
var pump = require('pump');
var rename = require('gulp-rename');
var uglifyjs = require('uglify-js-harmony'); 
var minifier = require('gulp-uglify/minifier');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
// END get gulp plugins

gulp.task('bundle_js', function () {
  // the same options as described above 
  var options = {
    preserveComments: 'license'
  };

  pump([
      gulp.src('scripts/*.js'),
      minifier(options, uglifyjs),
      concat('script_bundle.js'),
      gulp.dest('scripts_bundled')
    ]
  );
});

跑步:

gulp bundle_js

导致此错误:

throw err;
    ^

Error: Cannot find module 'gulp-uglify/minifier'
    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.<anonymous> (/home/me/Desktop/myGulpProject/gulpfile.js:6:16)
    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)

我尝试过的事情:

我尝试手动删除项目文件夹中的node_modules文件夹,然后运行:

npm install --save-dev

我也尝试过:

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

来自:https://stackoverflow.com/a/42090366/1063287

然后我尝试卸载并重新安装nodenpmgulp

npm uninstall gulp -g

sudo apt-get remove nodejs
sudo apt-get remove npm

来自:https://stackoverflow.com/a/33947181/1063287

cd /usr/local/lib/
sudo rm -rf node_modules/

cd ~
rm -rf .npm
rm -rf .npm-global
rm -rf .npmrc 

来自:https://stackoverflow.com/a/11178106/1063287

vim .profile // and commented out line added previously to address permission errors

从我的项目文件夹中删除了node_modules文件夹。

然后如上所述重新安装。

我仍然有同样的错误。

throw err;
    ^

Error: Cannot find module 'gulp-uglify/minifier'

0 个答案:

没有答案