gpt4 book ai didi

node.js 错误 : Cannot find module 'lodash.assign'

转载 作者:行者123 更新时间:2023-12-04 11:15:37 26 4
gpt4 key购买 nike

我已经在 windows 64bit 中安装了 node.js 并且在本地项目上 runnig 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']);

最佳答案

请尝试以下操作:

  • npm uninstall --save-dev gulp-jshint
  • npm uninstall --save lodash
  • npm cache clean
  • npm install --save-dev gulp-jshint

  • 不确定这是您的情况的问题,但有时 Node 缓存会困惑并出现类似的消息。基本上,lodash 应该作为 gulp-jshint 的依赖项安装安装该软件包时。除非您直接调用 lodash 的某些方法,否则您应该需要手动安装它。
    卸载后清理 Node 缓存,应从头下载并安装包,修复任何依赖错误。
    如果这有帮助,请不要忘记投票并标记答案:-)

    关于node.js 错误 : Cannot find module 'lodash.assign' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35160871/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com