node.js 错误:找不到模块“lodash.assign”
Posted
技术标签:
【中文标题】node.js 错误:找不到模块“lodash.assign”【英文标题】:node.js Error: Cannot find module 'lodash.assign' 【发布时间】:2016-05-11 16:40:50 【问题描述】:我已经在 Windows 64bit 中安装了 node.js,当我在本地项目上运行 gulp 时遇到了这个问题。
另一个注意事项:npm install 与 packages.json 配合得很好
Error: Cannot find module 'lodash.assign'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\NBCredit_FRTE\RelyToolsSln\RelyTools.Web\node_modules\gulp-jshint\node_modules\lodash.clone\node_modules\lodash._baseclone\index.js:9:14)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
PS D:\NBCredit_FRTE\RelyToolsSln\RelyTools.Web>
这是我的 package.json(我正在尝试设置这个项目:https://github.com/MarlabsInc/webapi-angularjs-spa)
"name": "webapi-angularjs-spa",
"description": "SPA Demo app with AngularJS",
"author": "Shiju Varghese",
"version": "0.5.0",
"repository": "https://github.com/MarlabsInc/webapi-angularjs-spa",
"devDependencies":
"gulp-util": "~2.2.14",
"gulp": "~3.9.0",
"gulp-concat": "~2.1.7",
"gulp-uglify": "~0.2.1",
"jshint": "~2.4.3",
"gulp-jshint": "~1.4.2",
"jshint-stylish": "~0.1.5",
"gulp-cssnano": "~2.1.0",
"gulp-rename": "~1.1.0",
"gulp-size": "~0.1.3",
"gulp-rimraf": "~0.2.0",
"gulp-open": "~0.2.8",
"gulp-connect": "~2.0.5"
,
"dependencies":
"lodash": "^4.2.0"
这是我的 gulp 文件:
var gulp = require('gulp'),
gutil = require('gulp-util'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
jshintreporter = require('jshint-stylish'),
minifycss = require('gulp-minify-css'),
size = require('gulp-size'),
clean = require('gulp-clean'),
rename = require('gulp-rename'),
open = require('gulp-open'),
connect = require('gulp-connect');
var filePath =
appjsminify: src: './Scripts/app/**/*.js', dest: './Scripts/app' ,
libsjsminify: src: ['./Scripts/libs/**/*.js', '!*.min.js', '!/**/*.min.js'], dest: './Scripts/libs/' ,
jshint: src: './Scripts/app/**/*.js' ,
minifycss: src: ['./Content/themes/**/*.css', '!*.min.css', '!/**/*.min.css'], dest: './Content/themes/'
;
gulp.task('app-js-minify', function ()
gulp.src(filePath.appjsminify.src)
.pipe(uglify())
.pipe(concat('ngscripts.js'))
.pipe(size())
.pipe(gulp.dest(filePath.appjsminify.dest));
);
gulp.task('libs-js-minify', function ()
/*Excludes already minified files.*/
gulp.src(filePath.libsjsminify.src)
.pipe(uglify())
.pipe(rename( suffix: '.min' ))
.pipe(gulp.dest(filePath.libsjsminify.dest));
);
gulp.task('jshint', function ()
gulp.src(filePath.jshint.src)
.pipe(jshint())
.pipe(jshint.reporter(jshintreporter));
);
gulp.task('minify-css', function ()
/*Excludes already minified files.*/
gulp.src(filePath.minifycss.src)
.pipe(minifycss())
.pipe(rename( suffix: '.min' ))
.pipe(gulp.dest(filePath.minifycss.dest));
);
gulp.task('clean', function ()
gulp.src(
[
'Scripts/app/ngscripts.js',
'Scripts/libs/angular-ui/select2.min.js',
'Scripts/libs/select2/select2.min.js',
'Scripts/libs/semantic/semantic.min.js',
'Scripts/libs/**/*.min.js',
'Scripts/libs/jquery-1.9.1.min.js',
'!Scripts/libs/jquery-ui-1.10.3.min.js',
'./Content/themes/semantic/semantic.min.css',
'./Content/themes/Site.min.css',
'./Content/themes/select2/select2.min.css'
], read: false )
.pipe(clean( force: true ));
);
gulp.task('build', ['app-js-minify', 'libs-js-minify', 'minify-css']);
gulp.task('cleanbuild', ['clean']);
gulp.task('tests', function ()
connect.server(
port:8000
);
var testUrl = "http://localhost:8000/SpecRunner.html";
gulp.src("./SpecRunner.html")
.pipe(open("", url: testUrl ));
);
//gulp.watch('./app/**/*.js', ['js']);
【问题讨论】:
嗯,你安装了lodash.assign
吗?试试npm i lodash.assign
。在尝试对您的项目做一些事情之前,您是否运行过npm i
?您可能缺少依赖项。
请提供一个相关的、最小的 gulpfile 副本来证明问题。目前没有足够的信息可以帮助您。
尝试更新你的 npm 和节点。
我运行 npm i lodash.assign
并运行 npm i
并得到同样的错误。我已编辑帖子以提供有关此项目的更多信息。
npm 版本:2.14.12
【参考方案1】:
尝试以下方法:
npm uninstall --save-dev gulp-jshint
npm uninstall --save lodash
npm cache clean
npm install --save-dev gulp-jshint
不确定这是否是您的问题,但有时节点缓存会混乱并出现类似的消息。基本上,lodash 应该在安装该软件包时作为 gulp-jshint
的依赖项安装。除非您直接调用 lodash 的某些方法,否则您应该需要手动安装它。
卸载后清理节点缓存,应从头下载并安装包,修复任何依赖错误。
【讨论】:
以上是关于node.js 错误:找不到模块“lodash.assign”的主要内容,如果未能解决你的问题,请参考以下文章
node.js 错误:找不到模块“lodash.assign”
Node.js 0.8.15 npm 错误:找不到模块 'proto-list'
面临错误:在运行 Node Js 服务器时找不到模块“C:\Users\DELL\Desktop\node js 程序\文件”