我有一个问题。我无法在Ubuntu 16.04上运行Gulp。所以, 我安装了Nodejs:
dmitriy@dmitriy-K53SD:~$ nodejs -v
v7.0.0
已安装npm:
dmitriy@dmitriy-K53SD:~$ npm -v
3.10.8
使用我的项目创建了一个文件夹。 通过命令初始化npm:
npm init
我在项目中添加了gulp:npm i gulp --save-dev
现在,我的package.json文件如下所示:
{
"name": "Test task",
"version": "1.0.0",
"description": "Front-end test fot Soft Industry",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dmytro Kovbasa",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1"
}
}
然后,我创建了文件gulpfile.js并且编写了一个简单的任务,例如:
gulp.task('hello', function() {
console.log('Hello world');
});
之后,当我尝试按命令运行此任务时:gulp hello
我一直在收到错误:
dmitriy@dmitriy-K53SD:~/work/D.Kovbasa front-end test$ gulp hello
/home/dmitriy/work/D.Kovbasa front-end test/gulpfile.js:2
gulp.task('hello', function() {
^
ReferenceError: gulp is not defined
at Object.<anonymous> (/home/dmitriy/work/D.Kovbasa front-end test/gulpfile.js:2:1)
at Module._compile (module.js:573:32)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.require (module.js:500:17)
at require (internal/module.js:20:19)
at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:198:16)
拜托,你能帮帮我吗?问题出在哪里?