我正在处理来自Mostly Adequate Guide by Professor Frisby的 Currying 主题,我尝试在实现浏览器无法运行npm
后通过require()
安装lodash。我一直在这里搜索使用类似的解决方案,但不起作用,我想让它在本地服务器上的节点上运行或使用script
,下面的结果仍然相同,{{1} }。
ramda
的package.json
Error: Cannot find module 'lodash.curry'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/Users/hueke32/Desktop/lodash_test/lodashTest.js:1:13)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Function.Module.runMain (module.js:431:10)
lodashTest.js
{
"name": "lodash_test",
"version": "1.0.0",
"description": "",
"main": "lodashTest.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"browser-sync": "^2.11.0",
"lodash": "^3.10.1"
}
}
的index.html
var curry = require('lodash.curry');
var match = curry(function(what, str) {
return str.match(what);
});
var replace = curry(function(what, replacement, str) {
return str.replace(what, replacement);
});
var filter = curry(function(f, ary) {
return ary.filter(f);
});
var map = curry(function(f, ary) {
return ary.map(f);
});
match(/\s+/g, "hello world");
match(/\s+/g)("hello world");
var hasSpaces = match(/\s+/g);
hasSpaces("hello world");
hasSpaces("spaceless");
filter(hasSpaces, ["tori_spelling", "tori amos"]);
var findSpaces = filter(hasSpaces);
findSpaces(["tori_spelling", "tori amos"]);
var noVowels = replace(/[aeiou]/ig);
var censored = noVowels("*");
censored("Chocolate Rain");
答案 0 :(得分:1)
lodash.curry
不是模块。 lodash
是一个以curry
为成员的模块。您应该如下更正您的要求。
var curry = require('lodash').curry;