gulp error | module path issue | module.js:471 throw err - gulp

I am new to gulp and getting this weird error. I am using node v6.9.1, tried with node v8 and v10 as well. Gulp was working fine on my system previously but facing this after i switched to nvm. I tried after npm uninstall, removing node modules, nvm cache clean, delete nvm folder but kind of struck here. Please suggest how to resolve this issue. when i do which gulp then i get msg no gulp in (env path).
gulp -v
module.js:471
throw err;
Error: Cannot find module ‘C:\(ProjectRepo)\Users(Uid)AppDataRoamingnpmnode_modulesgulpbin'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)

This is finally solved after lot solving series of issues. The above error was coming as i was working in a controlled env and npm i gulp was not installing all files and none under nvm directory. I copied them manually from another system both gulp & gulp-cli and it worked fine after that.

Related

package.json Not Found after using npm audit fix

I am trying to install sass and I don't understand why I keep running into the issue shown below
I understand I should follow the instructions and run npm audit fix but when I run the command, I get an error of no package.json found, and yes, that is so because sass wasn't installed at all and thus no node-modules and the json file, how do I fix this issue?
Try running the npm init command at the root of your project to generate the package.json file and re run the command to install sass.

Gulp bundle --ship: The build failed because a task wrote output to stderr

I've been getting this error when trying to do a gulp bundle --ship command:
The build failed because a task wrote output to stderr.
Exiting with exit code: 1
I'm pretty new to this so have no idea how to proceed with it. It's happening even when I run through the helloworld webpart now. The gulp serve works and I can bundle and package the solution as long as I don't add a --ship to it. I've written and published apps before on the same machine so I don't know what is different now.
I've uninstalled every extension and re-installed the application but it's still doing it. Any help would be appreciated.
Just for quick win you can use --debug flag for bundling task instead of --ship until this bug will be fixed in future releases:
gulp bundle --debug
gulp package-solution --ship
The bundled file will be bigger, but at least you are not getting "The build failed because a task wrote output to stderr" error in CI/CD.
It normally happens because of the warnings. You can add suppression like mentioned below in gulpfile.js
build.addSuppression(Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.);
build.addSuppression(/Warning/gi);
I got this error because caniuse-lite needed a database update. It was confusing because there was no red error message.
Easy fix: npx browserslist#latest --update-db

Npm - Unexpected token } in JSON at position 0

Yesterday I installed the JSDoc package using npm install -g jsdoc and used it just fine. Today when I tried to use it again, I got the following error:
module.js:96
throw e;
^
SyntaxError: Error parsing ...npm\node_modules\jsdoc\node_modules\requizzle\package.json: Unexpected token } in JSON at position 0
at Object.parse (native)
at readPackage (module.js:92:52)
at tryPackage (module.js:102:13)
at Function.Module._findPath (module.js:172:20)
at Function.Module._resolveFilename (module.js:438:25)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
I've actually gotten this numerous times before and a clean reinstall of the package fixes it, but I was wondering what keeps causing this error and if a more permanent fix were available.
When I open up the package.json file mentioned in the error, it looks like a binary file with a bunch of weird symbols.
I see that the first character is a } which kinda explains the error. Thing is all the package.json files for every package I download looks like that, and it works the first time so npm apparently can parse this.
EDIT:
Quick note: I am on my office laptop.
Ok so I cleaned out the node_modules folder and reinstalled jsdoc with npm install -g jsdoc. I checked the package.json file: it's all plaintext and looks great.
I then shut down and start up my computer. Not only is the jsdoc package.json file obfuscated, the package.json files of all its dependencies are also obfuscated! This little bug is recursive!
To test it further, I took the json file, duplicated it and renamed it PACKAGE_DUP.json and placed it right next to the original json file. I also took the node_modules folder and made a copy called NODE_MOD_DUP, again next to the original. So now there are 4 package.json files:
node_modules/package.json
node_modules/PACKAGE_DUP.json
NODE_MOD_DUP/package.json
NODE_MOD_DUP/PACKAGE_DUP.json
When I restarted my computer, the only json file affected was the package.json file in the node_modules folder (item number 1). So it's being targeted by something!
Virus scans are coming up clean, and every other json file in the modules folders and on my system as a whole are completely unscathed. Also, the package.json files that come with the modules bundled with node work fine. It's only modules installed with npm install that are giving me a problem (whether installed globally or locally for that matter).

Aurelia bundle with gulp throws "TypeError: Path must be a string. Received undefined"

I'm using the skeleton-typescript aurelia skeleton-navigation package, when running gulp bundle it gives me an error that says path must be a string but was undefined
TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.basename (path.js:801:5)
at exports.writeOutputs (C:\Users\joaoe\Desktop\skeleton-navigation\skeleton-typescript\node_modules\systemjs-builder\lib\output.js:137:23)
at C:\Users\joaoe\Desktop\skeleton-navigation\skeleton-typescript\node_modules\systemjs-builder\lib\builder.js:575:14
at tryCatcher (C:\Users\joaoe\Desktop\skeleton-navigation\skeleton-typescript\node_modules\systemjs-builder\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\joaoe\Desktop\skeleton-navigation\skeleton-typescript\node_modules\systemjs-builder\node_modules\bluebird\js\release\promise.js:502:31)
All gulp related files can be found here since there are more than one.
Even the cloned package throw that.
I'm running Node 6.0.0 and tested with 5.9.1, on Windows 10.
There is some property that I need set to be that path ? Seems related to Aurelia pre built tasks, from comments could also be an environment problem.
As I tracked it down, the issues seems to be an ugly combination of node-gyp, Windows and node 6
So install all dependencies needed for node-gyp, following your OS steps as seen at official repo. Unfortunately for now if you are running Windows is likely that you need to install Visual Studio. Then run npm install on the repository and see if there is any error, should be no one now. Then try to gulp bundle it should work now. With downgraded node to 5.11 I was able to run again, I did not test with node 6 but feel free to try.

Error: Requiring external module babel-register

sw_vers && node -e 'console.log(process.platform, process.versions)'
ProductName: Mac OS X
ProductVersion: 10.11.3
BuildVersion: 15D21
darwin { http_parser: '2.6.0',
node: '5.2.0',
v8: '4.6.85.31',
uv: '1.7.5',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '47',
openssl: '1.0.2e' }
node -v
v5.2.0
gulp -v
Requiring external module babel-register
CLI version 3.9.1
Local version 3.9.1
Getting error when running gulp serve, I've fixed this before by removing the entire webapp repo from local. Any and all help/advice appreciated, also please forgive if I've not formatted this issue as correctly as possible(first issue ever opened). Would like to resolve this without having to do this. gulp serve throws the following:
Running yeoman generator "Webapp", I'm getting an error when running gulp serve. Here are the following versions for a better background :
sw_vers && node -e 'console.log(process.platform, process.versions)'
ProductName: Mac OS X
ProductVersion: 10.11.3
BuildVersion: 15D21
darwin { http_parser: '2.6.0',
node: '5.2.0',
v8: '4.6.85.31',
uv: '1.7.5',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '47',
openssl: '1.0.2e' }
node -v
v5.2.0
gulp -v
Requiring external module babel-register
CLI version 3.9.1
Local version 3.9.1
Finally the gulp serve error:
gulp serve
Requiring external module babel-register
\node_modules/babel-core/lib/transformation/file/options/option-manager.js:372
throw new Error("Couldn't find preset " + JSON.stringify(val) + " relative to directory " + JSON.stringify(dirname));
Does anybody have any idea what the problem could be, any suggestions?
Here's what I've tried:
npm uninstall gulp
npm install gulp
//with global flag and not
npm install --save-dev gulp
//installing babel-register manually w/wo global flag and --save-dev
npm install babel-register
npm cache clean
I had a very similar issue with running a custom project that was originally created using the Yeoman Webapp generator and found a solution that worked for me. A bit of context... the project was running fine on my Windows 7 machine and when I tried to move it over to my Mac OSX machine I received the exact same error. What I found works is creating a new Yeoman Web App project and drag & dropping the exact node-modules folder structure over to your existing project. Most likely than not, there is a dev dependency that your machine is not reading and fetching accurately, in this case, the babel-register module which is contained within this node-modules folder.
If possible for you to do, it's also worth comparing the versions of node, npm, gulp, gulp cli with your previous working version and the version you are having trouble loading when running gulp serve to see if they match.