Cannot find module './version' - npm install on Azure DevOps fails - node.js

I'm encountering a problem with the npm install step during my CI/CD build in Azure DevOps.
The specific package that is causing this problem appears to be node-sass. This package has given me a lot of trouble in the past as well but I did get it working and builds have been running fine for a while. Now for some reason they are failing again but I cannot seem to reproduce the problem on my machine and the error doesn't make any sense to me.
Here is the output from the failed build: https://pastebin.com/w4aK4dEh.
The error message is "Error: Cannot find module './version'"
I have tried to modify the step and changed it from a simple npm install to npm install --save-dev --unsafe-perm but it didn't seem to have any effect.
package.json
{
"version": "1.0.0",
"name": "myproject",
"private": true,
"devDependencies": {
"gulp": "4.0.2",
"gulp-concat": "2.6.1",
"gulp-cssmin": "0.2.0",
"gulp-rename": "2.0.0",
"gulp-sass": "4.1.0",
"gulp-uglify": "3.0.2",
"rimraf": "3.0.2",
"node-sass": "^4.8.3"
},
"dependencies": {}
}
I have also tried to remove node-sass from the dependencies entirely because I thought gulp-sass already includes it by default, but then I ran into "module node-sass not found" errors.
I'm really stumped on this one. Any suggestions would be appreciated.

I am not entirely sure which of the following was the key to success but here's what I did to resolve this:
Delete the node_modules folder from my project, commit and then modify my .gitignore to exclude it from the repository permanently (yes, I know this one is a bit controversial as some people say the folder should be checked in)
Update the versions of the dependencies in the package.json file
Specify the specific version of NodeJs (and thus npm) to use. I did this by simply adding a step in the Azure build pipeline. Interestingly, the very latest version (15.2.1 at the time of writing this) did not work, however the LTS version 14.15.1 did work.
Some combination of those three changes did resolve the problem for me. I am leaving this information here in case someone else faces this same error message.

Related

npm install stuck on "checking installable status"?

I have recently updated a project where the last udpate was about a month ago, but failed to deploy to the server. After some investigation, it is because it is stuck in npm install, or more precisely, stuck at a line saying
This sutck happens on different package when trying on different machine, so it seems to be related to npm instead of any package.
I have made no changes to the package.json, only on some other javascript files. Also, the last deploy was about a month ago. In other words, the npm install can be run without problem last month.
This problem can be replicated by copying the package.json file to an empty folder and run npm install. The package.json file:
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^6.0.0-14",
"laravel-elixir-webpack-official": "^1.0.2",
"node-sass": "^4.5.3"
},
"dependencies": {
"eventemitter3": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-1.2.0.tgz"
}
}
I am using node 11.15.0, npm 6.7.0 through nvm. As it is a running project on live, upgrading or downgrading node and npm version is not an option without some careful planning, and seems to be an overkill at the moment.
For reference, I noticed that there is an outage in npmjs registory recently, but it seems to be fixed, so I am not sure if it is related. Have anyone had similar problem recently? Or any suggestion on how to solve this problem?

Gulpfile not found even though it clearly exists

I'm trying to help a remote coworker install gulp on Windows so he can compile one of our JavaScript projects locally. An employee before me has been trying to help this remote coworker for over a year before I got here to little avail, so there may be some crud left over from that time at the root of the issue, but I've done what I thought to be a reasonable start from scratch and I continue to have the same problem.
I've sent him the project folder exactly cloned as I have it, minus the node_modules folder. I had him uninstall and reinstall Node first using the first three steps of this answer followed by redownloading the MSI from NodeJS.org to reinstall fresh. Then, in the working directory, I had him run
PS C:\Users\Coworker\Path\To\Project>npm ci
to install gulp. gulp and its various extensions are the only modules in the package.json folder, and the package-lock.json is simply the result of us successfully installing these packages recently. Contents of package.json:
{
"devDependencies": {
"gulp": "^4.0.0",
"gulp-coffee": "latest",
"gulp-concat": "latest",
"gulp-concat-sourcemap": "latest",
"gulp-connect": "latest",
"gulp-minifier": "latest",
"gulp-minify-css": "latest",
"gulp-remove-logging": "latest",
"gulp-resolve-dependencies": "latest",
"gulp-sass": "latest",
"gulp-uglify": "latest",
"gulp-util": "latest",
"gulp-watch": "latest",
"gulp-wrap": "latest"
},
"dependencies": {
"natives": "^1.1.6"
}
}
I also had him uninstall and reinstall gulp-cli globally.
npm uninstall --global gulp gulp-cli
npm install --global gulp-cli
Running gulp --version displays the correct, expected output:
PS C:\Users\Coworker\Path\To\Project>gulp --version
CLI version: 2.2.0
Local version: 4.0.0
This matches the output on my Windows machine, where everything works fine.
When we finally have him run gulp in the project directory, it simply gives:
PS C:\Users\Coworker\Path\To\Project> gulp
No gulpfile found
The only helpful question already on Stack Overflow for this is here, and every answer there is some form of "add a gulpfile". But there is a gulpfile.js in the working directory. It has the correct name and file extension. It is formatted properly. It's an exact duplicate of the file in my own local directory, which when I run the same command, it gulps flawlessly. What could be causing gulp to not recognize the gulpfile is present? Could gulp be misconfigured and trying to run with a different working directory, despite the directory it is being called in? How can I troubleshoot this?
Try explicitly specifying the gulpfile:
gulp --gulpfile gulpfile.js
gulp --gulpfile C:\Users\Coworker\Project\gulpfile.js

Can't install laravel-elixir because of node-sass failure

I am pretty new to this environment still and am trying to get up to speed on node.js modules and Laravel (5.1.11) as a whole, so...
I have a fresh install of Laravel implemented by the cPanel Installitron. I'm using PHPStorm to install all of the node modules via the provided package.json:
package.json
{
"private": true,
"devDependencies": {
"gulp": "^3.8.8"
},
"dependencies": {
"laravel-elixir": "^3.0.0",
"bootstrap-sass": "^3.0.0"
}
}
The error I get when I run the install is:
Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-57_binding.node":
HTTP error 404 Not Found
I can understand why this would happen, seeing as that is an older version of node-sass, but how do I know what newer versions are compatible with the requested version of laravel-elixir? I didn't want to just install a newer version of node-sass because digging a deeper hole would make it harder for me to find a solution to my problem. What is the fix for this?
It looks like you can fix this by installing Windows Build Tools via this command:
npm install --global --production windows-build-tools
Then delete the project's node_modules folder and re-run npm install.
Just follow this official url well doc.: https://laravel.com/docs/5.3/elixir if you get any error. I just comment and i ll be here.

Unable to resolve module `react/lib/ReactComponentTreeHook`

I'm attempting to upgrade React Native and I'm running into the following:
error: bundling: UnableToResolveError: Unable to resolve module `react/lib/ReactComponentTreeHook` from `/Users/anthony/dev/apptova-react/node_modules/react-native/Libraries/Performance/Systrace.js`: Module does not exist in the module map or in these directories:
/Users/anthony/dev/apptova-react/node_modules/react-native/node_modules/react/lib
, /Users/anthony/dev/apptova-react/node_modules/react/lib
I'm so confused. I can't find any library named ReactComponentTreeHook in node_modules, anywhere.
I've tried removing the node_modules folder and reinstalling, nada. I've also cleared watchman watches and reset the packager cache.
EDIT: I kept running into issues that seemed to stem from react-native-maps so I so I reset back to a working stable version, uninstalled react-native-maps, and ran react-native-git-upgrade (again).
Now I'm getting:
error: bundling: UnableToResolveError: Unable to resolve module `react/lib/ReactDebugCurrentFrame` from `/Users/anthony/dev/apptova-react/node_modules/react-native/Libraries/Renderer/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js`: Module does not exist in the module map or in these directories:
/Users/anthony/dev/apptova-react/node_modules/react-native/node_modules/react/lib
, /Users/anthony/dev/apptova-react/node_modules/react/lib
I'm just trying to latest, my package.json dependencies are simple so I don't think its conflicts with a third-party code base:
"dependencies": {
"react": "15.4.1",
"react-native": "^0.43.1",
"react-native-drawer": "^2.3.0"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-plugin-transform-flow-strip-types": "^6.21.0",
"babel-preset-react-native": "1.9.1",
"deepmerge": "^1.3.2",
"flow-bin": "^0.37.4",
"jest": "18.0.0",
"react-test-renderer": "15.4.1"
},
Again, went throught the process of clearing watchman watches, node modules, reseting package manager and still get this error.
EDIT 2: After spending two solid days of trying to get this working I created a new blank project and migrated my code over.
Make sure version in your package.json file is the version you want.
For example, "react-native: ^0.43.3" is not same as "react-native: 0.43.3".
Clean up and re-install everything.
If the error still there, then try to install react-native-git-upgrade
$ npm install -g react-native-git-upgrade
and then run
$ react-native-git-upgrade x.y.z(version you want to upgrade to)
for me it works.
If your version is too old, then you should follow the old version document to upgrade.
This could also happen if you don't have the correct version of react required by the version of react-native. If this is the case, you would get a warning like this when you run npm install.
npm WARN react-native#0.43.4 requires a peer of react#16.0.0-alpha.6 but none was installed.
To fix this problem, stop the react packager and upgrade the version of react by running the following command
npm install -save react#16.0.0-alpha.6
Now, re-run the app and hopefully the issue would go away.
I think recently many of the modules under react/lib were moved to react-dom/lib, which is why the packager can't find some modules
I followed following steps and it's working
• Deleted node_modules folder
• Replaced ^16.0.0-alpha.6 with "react": "16.0.0-alpha.3"
• npm install
• react-native run-android

npm private modules error

I've couple of private modules that are not on the npm site and I'd like to use them in my application but running in couple of issues while uploading at Elasticbeanstalk. (Elastic beanstalk runs it's npm install after each upload).
The AWS complained initially that it couldn't find those private modules on NPM, so I removed their entries from package.json file.
Once I removed, I uploaded the application again with node_modules folder having those packages then AWS start to complain
Error: Cannot find module 'my-private-module-name'
I'm wondering how private modules work so I don't have to go through NPM at least for deployment or as a last resort I'll publish them.
Edit
"dependencies": {
"body-parser": "^1.12.4",
"express": "^4.12.3",
"multer": "^0.1.8",
"mustache": "^2.0.0",
"mysql": "^2.6.2",
"my-private-module": "^1.0.5",
"redis": "^0.12.1",
"socket.io": "^1.3.3"
},
You will need to have an internal way of publishing packages if you wish to not have certain packages looked up on npm.
In your individuals packages you will need to add
"publishConfig":{"registry":"http://my-internal-registry.local"}
to the package.json file.
This will allow you to look up packages at that location as opposed to going directly to NPM.
https://docs.npmjs.com/misc/registry
Then in your ~/.npmrc file you can specify a registry that npm will use first prior to looking up modules on npm.

Resources