Closed smeijer closed 9 years ago
Hello!
I had this problem on Windows and usually one of the following fixes it:
npm install gulp
on the project folder, even if you have gulp
installed globally.PATH
. The package will try to get the PATH
from the environment, but you can override it by adding exec_args
to your gulp settings. For example, on Linux I have:"exec_args": {
"path": "/bin:/usr/bin:/usr/local/bin"
}
Let me know how it goes!
Gulp is installed globally as well as locally. So that doesn't seem to be the problem.
Any idea what to add specifically to the "path"? My Windows environment path setting seems to be alright, and overriding them trough the config doesn't seem to help.
I've tried the following paths in the exec_args.path property, but they don't fix the "gulp is not defined" error.
The paths seems to be allright too...let's see.
That error is thrown by the js
that gets run by node behind the scenes so the package can get the gulp task list (overcomplicated, I know, but there wasn't a gulp tasks
at the time).
So what it does is:
var requireGulp = function(gulpfilePath) {
// Read your gulpfile.js
var fileSrc = fs.readFileSync(gulpfilePath);
// add the exports at the end so it can be required by node
fileSrc += ";module.exports = gulp;";
// write the temporal file
fs.writeFileSync(tmpfilePath, fileSrc);
try {
// require the new 'gulpfile', with module.exports = gulp; at the end
return require(tmpfilePath);
} catch(ex) {
// On error, delete the tmp file and throw (the one that gets printed to the log)
fs.unlink(tmpfilePath);
throw ex;
}
};
So!, if you don't mind, try adding module.exports = gulp;
to the end of your gulpfile.js
and then running the following on your console:
node -e "var gulp = require('./gulpfile.js'); console.log(gulp);"
When I do it, it logs the gulp
object to the console
(sorry for the inconvenience)
Briljant! I've just fixed it. Well, you did actually.
The problem was my way of setting up gulp. My gulpfile.js never required gulp itself. This works, because I separate my tasks into individual js files. My gulpfile.js looks like this:
var fs = require('fs');
var path = require('path');
var jsfiles = function(name) {
return /(\.(js|coffee)$)/i.test(path.extname(name));
}
var tasks = fs.readdirSync('./gulp-tasks/').filter(jsfiles);
tasks.forEach(function(task) {
require('./gulp-tasks/' + task);
});
Appending a require to the file, fixed the problem. Export isn't required.
// require(d) gulp for compatibility with sublime-gulp.
var gulp = require('gulp');
Wow I never thought of that, it's a good idea.
I think I'll add an explanation to the README that covers this case (and I think I'll start using something similar :P), thanks a lot for letting me know what it was!
I just can't get it working on Windows. Gulp runs fine from command, but sublime-gulp is throwing the error below to it's log. Any idea how to get this working?