Cannot install vue - node.js

I usually perform fresh re-installs of packages after a period of non-use, but when I came to perform a fresh install of Vue.js and vue-cli I tried to perform a vue init on a new project but was told that vue was not recognised as an operable or batch file etc.
It is possible that I created a problem when I uninstalled vue-cli, which removed something like 250 packages. Subsequent reinstall only installed 1 package, but I was then unable to get any response from the vue init command other than the above.
I have tried every workaround I could find on SO and elsewhere which boils down to the following: -
Upgrading node and npm
Upgrading git
Cleaning the npm cache
One consistent error message in my attempts to perform npm install vue was that I lacked a package.json file in my C:/Users/user folder (I am said user and I have administrator privileges). I ran npm init to create a blank package.json file in that folder but that didn't work either.
The root problem seems to be that nothing I do re-installs a vue.cmd file in my AppData/Roaming/npm folder, even though this path is properly installed in my environment variables. I have looked if this file has been installed elsewhere on my machine, but it hasn't.
Is it possible to manually download a vue.cmd file and put it exactly where it needs to sit, i.e. in my AppData/Roaming/npm folder? I googled this to no avail. All this is while running Command Prompt as an administrator.
Is anyone else having this problem? Is there something with another JS framework which is currently blocking Vue from being properly installed? (I have also developed projects in React and Angular5.)
Just as an update, this is the package.json file I currently have in my C:/Users/user folder after running npm init from that folder: -
{
"name": "user",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"npm": "^5.8.0",
"vue": "^2.5.16"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

It sounds like you don't have vue-cli installed on your machine
But without any error messages it's impossible to tell.
try npm install -g vue-cli#2.9.3
then run which vue-cli to check the location

Related

NodeJS installed modules are not recognized on Windows 10

I need some help to setup NodeJS on a Windows 10 machine.
I installed the 10.15.3 LTS version from the official website which has done the following:
Node installed at C:\Program Files\nodejs\
Added to the Path in the user's variables: C:\Users\rsantos\AppData\Roaming\npm
Added to the Path in the environment variables: C:\Program Files\nodejs\
Created an empty npm folder at: C:\Users\rsantos\AppData\Roaming
Then with npm init I initialized the package file which was created at C:\Users\rsantos.
Followed by npm install supervisor which:
Created a npm-cache folder at C:\Users\rsantos\AppData\Roaming\npm-cache
Created a node_modules folder (with the supervisor) at C:\Users\rsantos\node_modules
Created a package-lock.json file at C:\Users\rsantos with:
{
"name": "rsantos",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"supervisor": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/supervisor/-/supervisor-0.12.0.tgz",
"integrity": "sha1-3n5jNwFbKRhRwQ81OMSn8EkX7ME="
}
}
}
Updated the package.json file to:
{
"name": "rsantos",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"supervisor": "^0.12.0"
}
}
Then when I open the command line and type:
C:\Users\rsantos\Desktop>supervisor --watch C:\NodeJS_Projects\Proj1\ -e js C:\NodeJS_Projects\Proj1\Test.js
I get:
'supervisor' is not recognized as an internal or external command, operable program or batch file.
After that I tried to install supervisor globally and it started to work.
The next error was 'require' not being recognized after installed locally.
I followed the same approach which made supervisor work and installed require globally. My code is requiring the module with require('request'). But even installed globally, it fails with this error:
Error: Cannot find module 'request' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
Notes:
I uninstalled everything and reinstalled, the result was always the same.
Also played with the environment variables but still no good.
npm list -g request outputs this: C:\Users\rsantos\AppData\Roaming\npm -- request#2.88.0
At this point my C:\Users\rsantos\node_modules folder has all the modules, including supervisor and request.
The package.json has supervisor and request as dependencies.
The package-lock.json seems to have all the modules in the node_modules folder, including supervisor and request.
I still get the Cannot find module 'request' error.
Can someone help please?
when you want to use a NPM package as tool (e.g. >supervisor --watch PATH), you can install the package --global. When you want to load the package in Node with require() I would install it locally.
Does the following work for you?
Install the tooling globally:
npm install --global supervisor
Set up your project in local folder:
mkdir project
cd project
npm init -y
npm install --save request # install to project/node_modules
node index.js # start your app

Managing Node JS dependencies

I am learning node js and I have put together a small website which is using a few dependencies like jquery and a couple of other js files. When it comes to moving the site to a live server how do I migrate the dependencies that I used in production? Would I have to download the jquery files and other js library files then add the link into my script tags like you normally would as I guess everything in production points at the node_modules folder?
Sorry for sounding a little daft but I’m still learning my way with npm.
Appreciate any advice
Rufus
In Node.js, server side dependencies are saved in the package.json file and these describe any dependencies you'll need.
You create this file by typing
npm init
This will prompt you for some details (which you can skip with -y flag.)
To install your server side dependencies, I presume you've used:
npm install <dependency>
To ensure this is saved you can type
npm install <dependency> --save
e.g.
npm install lodash --save
This will update your package.json.
package.json should be stored in source control and your dependencies can be restored using:
npm install.
An example of a package.json file would look like this:
{
"name": "node_test_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.11"
}
}
If you see a package-lock.json file (later versions of NPM), this should be added to source control too.
Personally I just use npm install lodash
Then
app.use('/scripts/lodash', express.static(__dirname + '/node_modules/lodash/'));
that way I can use this as (in node.js)
const _ = require('lodash');
or in an html file as
<script src='/scripts/lodash/lodash.js'></script>
Preventing the whole "copying to public/js"...
Or if you're just talking about a build process, you just run npm install on your productions server and it installs all the packages from packages.json again.

webpack error on build run. 'Error: Cannot find module '#webassemblyjs/ast''

I' am currently working in React, and I'm trying to setup webpack and webpack-cli. I am currently following the tutorial on webpack 4 tutorial site https://www.valentinog.com/blog/webpack-4-tutorial/ using my command line I've been trying to install webpack and webpack-cli as my dependencies using nodejs.
I've been entering npm i webpack --save-dev and npm i webpack-cli --save-dev
Both these modules install correctly and are added to my package.json as dependencies.
{
"name": "webpack-4-quickstart",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.10.1",
"webpack-cli": "^2.1.4"
}
}
I also have a scripts section that has a "build": "webpack" which should initialize my webpack. But when I type npm run build i get this error. Error: Cannot find module '#webassemblyjs/ast'. I've checked my node_modules and #webassemblyjs is there.
I've tried uninstalling my node_modules, reinstalling webpack and webpack-cli and even moved to a different directory and repository to see if I could change my outcome that way. However, I'm still getting this cannot find module #webassemblyjs/ast. I'm currently running MacOs High Sierra, and am not sure if maybe it's just not agreeing with my operating system. If anything I haven't noticed any other Stackoverflow posts dealing with this specific error, so I thought I'd make a post asking for help.
Thankyou for your time!
I had the same problem. After trying many variations of version, deleting node modules a couple times, trying to manually install the library, I finally solved it by running
npm ci
~1 day hours of debugging, 6 letter command. Computers are so fun sometimes
try this
update "webpack": "^4.10.1" to "webpack": "^3.11.0"
No issues on macOS High Sierra with:
"devDependencies": {
"webpack": "^4.12.0",
"webpack-cli": "^3.0.8"
}
Try first upgrading to those versions and see if that resolves the issue.
Also, are you using a private registry? If so, you might be getting something like this if #webassemblyjs can't be found in it:
npm ERR! code E404
npm ERR! 404 Not Found: #webassemblyjs/ast#1.5.12
You could quickly fix this by adding #webassemblyjs:registry=https://registry.npmjs.org in your .npmrc file.
Otherwise, you could try running webpack --display-error-detail and see if you get additional details about the error.

node local dependency installs as shortcut and nested instead of flat

It seems this started when I updated node/npm but I didn't realized until now when I had to delete and re create my node_modules folder.
I have a React Native project which has the core module and one Examples project to showcase the module. The examples project references the module like this in my package.json:
"dependencies": {
"module-core": "file:../core"
},
When I run npm install in the Examples project I was getting this nodule_module structure:
node_modules
core
core_dependency_1
core_dependency_2
Now, I get this:
node_modules
core
node_modules
core_dependency_1
core_dependency_2
At first I thought it had to do with peerDepencies and how npm handled flat/nested dependencies but I have checked and it seems now the core folder is now a shortcut (I am using Windows).
This is breaking my gradle scripts because some are referenced like this:
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
I could fix this by renaming the links but that would make the build platform/environment dependent.
Also it breaks some other scripts like this one:
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
That is because the project() resolves to my root folder and now I cannot use that either.
I am using npm 5.4.2 and node 8.8.1. Previously I had node 7.4.0.
Is there any flag or way to make npm install the localDependency and not treat it as a shortcut?
I finally found the answer. Npm Version 5 indeed changed the way the local dependencies are handled and it just makes npm link, which creates symbolic links or shortcuts in windows.
You can accomplish the same behavior as before with this:
npm install $(npm pack <folder> | tail -1)
Working for me in Windows 10 with git-bash
My final solution was having this package.json in the Example project that used the core:
{
"name": "core-examples",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"preinstall": "npm pack ../Core | tail -1",
},
"dependencies": {
"core": "file:core-0.0.0.tgz"
},
"jest": {
"preset": "react-native"
}
}
The preinstall script will generate the tgz file and then you can install as usual. This will avoid having to commit the tgz file to the repository.

AWS Elastic Beanstalk run Grunt task

I want to run a node.js application on elastic beanstalk. I have a client which gets build by a grunt job (jade, less, concat, etc.) I excluded this folder from git
I can localy run this by grunt buildClient which is executed by grunt-cli
I added grunt and grunt-cli in my packages dev-dependencies
I want to run the grunt build before the application is launched, i already setup a configuration in .ebextensions/app.config
container_commands:
01_build_client:
command: grunt buildClient
I guess my cwd is /tmp/deployment/application/
but there is says Fatal error: Unable to find local grunt. I guess grunt-cli is installed, but why is this error?
i also tried putting the grunt job in the postinstall section of package.json, but this doesnt work as well.
How do i build my grunt job on a EBS instance?
When running Grunt on a paas, it's best to install a local copy of grunt-cli and grunt locally in the project. That way it's always available and is the exact version you'll need. Then you run npm install instead of grunt so your postinstall works properly.
For example, your package.json might look like this:
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
You can first specify the path to your gruntfile using the --gruntfile <pathToGruntfile> option on the grunt command. However, you'll also need to npm install grunt before running this, or you'll receive the same error.
I've just run into a similar problem whilst trying to get webpack bundilng on elastic beanstalk. I found that when elastic beanstalk runs an npm install it includes the --production flag. This means that you'll need to move your dev dependencies into the dependencies block.
Something else that caught me out is that eb doesn't seem to run the postinstall script which is really annoying! I did find that it runs the prestart script though.
My package.json file ended up looking something like this:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"prestart": "node node_modules/webpack/bin/webpack.js"
},
"dependencies": {
"backbone": "^1.2.1",
"backbone.marionette": "^2.4.1",
"webpack": "^1.9.10",
...
}
}

Resources