ReferenceError: Cannot access ‘devBuild’ before initialization
at Object. (C:\Users\riadk\Desktop\projectsamle\gulpfile.js:11:16)
Does anyone have an idea what is happening here and why this is broken. I cannot figure out why a tutorial from Sitepoint would give broken code…
Here is the full cli call:
riadk@RIADS-LAPTOP MINGW64 ~/Desktop/projectsample/src (master)
$ gulp css
[02:36:04] Working directory changed to ~\Desktop\projectsample
C:\Users\riadk\Desktop\projectsample\gulpfile.js:11
stripdebug = devBuild ? null : require('gulp-strip-debug'),
^
ReferenceError: Cannot access 'devBuild' before initialization
at Object.<anonymous> (C:\Users\riadk\Desktop\projectsample\gulpfile.js:11:16)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at execute (C:\Users\riadk\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18)
at Liftoff.handleArguments (C:\Users\riadk\AppData\Roaming\npm\node_modules\gulp-cli\index.js:201:24)
at Liftoff.execute (C:\Users\riadk\AppData\Roaming\npm\node_modules\gulp-cli\node_modules\liftoff\index.js:201:12)
If so, which is the section with the code that is giving you the error? It would be helpful if you could provide steps to reproduce the error you are having.
Anything is possible — a version mismatch, typo etc.
The part that I am getting the error is under [HTML Tasks] The same issue will happen under the JavaScript tasks as well. It has something to do with the `.pipe devBuild ? noop html clean
This ran without error and minified my sample HTML file as expected.
Please note, I set the devBuild variable to false for testing purposes and also that I have a linter set to automatically lint the code, so this will also look a bit different from what’s in the book.
Could you give that a go and let me know how you get on.
That works, thanks. Could you explain a little more what exactly was wrong so I can try to fix it on the JS section as well. I’d like to know what the error was for future.
I’m also getting a lot of errors following this tutorial. When you suggest amendments can you ask the author to note the node and npm versions they are using. And, as a bonus it would be helpful to have the complete gulpfile.js attached at the end of the tutorial to make sure nothing is missed out.
That works, although it does throw errors for autoprefixer (already flagged above).
I’m confused with the goal of An Introduction to Gulp.js, I was expecting to step through adding browser-sync and creating a gulp watch command. My goal was to setup a gulp project where I could edit html, js, scss and see changes replicated in a live environment.
You can also do this with webpack. Webpack itself would take care of the SCSS > CSS transpilation, whereas webpack-dev-server would provide the live dev environment.
Here’s a a tutorial on setting up webpack.
I just followed it through to make sure I’m not recommending anything outdated (JavaScript changes waaay to quickly) and can confirm that it works as expected
If you’re not too invested in Gulp, I would give that a go and see if it fits your needs.
And BTW, webpack also brings some further benefits to the table, such as allowing you to write your JavaScript using modules (which it will bundle) and the latest syntax (which it will transpile).
Actually, thinking about it, this npm package may be better suited to your needs.
You’d still need some way of compiling SCSS to CSS, but you could do this with Webpack or with Gulp.
You would install live-server on your machine globally, then use it to serve your site. Simultaneously, you’d kick off your SCSS > CSS transpilation using a watch flag, so that it would recompile when you make any changes.
I’ve used Gulp in the past with browser-sync. I wanted to upgrade to v4 and migrate some existing projects over.
To confirm, the desired outcome for someone following the An Introduction to Gulp.js tutorial is to create a gulp file, do some setup, then move onto webpack. Is there somewhere where I can provide feedback on this?
Not really. If you have an old Gulp project running successfully with Browser sync, then I would upgrade that. From what you posted above, it sounded like you were new to using Gulp. My replies were just how I would go about tackling the problem you outlined.
You can leave a review on the book page, or you can post here. I can make sure that any feedback gets passed on.