I'm not very used to working with node and I'm having a nightmare installing the packages for a project.
I'm using vagrant/VirtualBox Homestead on Windows 10 for a Laravel (5.2) project. When doing npm install I've had a whole bunch errors - I can't remember them all specifically, but I'm wondering if there is some big picture issue I'm missing.
My first attempt was with a recent node node version - 12.something I think.
Then I was told that "some of those older projects used v8, I think", so I used nvm to do that and got a whole bunch of different issues. Some involved sym links, so I deleted node_modules and tried with --no-bin-links. That didn't work, and one of the errors, when I looked on SO, was down to node version, so I tried v9.0.0, which gave different problems.
How hard can it be?
I don't know enough about this frontend stuff to know if it's normal to have so much trouble, or if I have not been given sufficient information - e.g. "you absolutely need to use node version 8.1.3, with these specific other details..." or something like that.
Does anyone have any suggestions on how to get this working? The node-sass package seems to be a significant culprit in the overall failage of the installation...
Below is my package.json
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^5.0.0",
"bootstrap-sass": "^3.0.0"
},
"dependencies": {
"node-sass": "^4.1.0"
}
}
I was heading same problem last time. Here is what I did:
Using terminal in homestead directory run command vagrant plugin install vagrant-winnfsd it will install plugin that allows you to use NFS protocol on Windows.
Edit you Homestead.yaml file like that:
folders:
- map: ~/Projects
to: /home/vagrant/code
type: "nfs"
Run command vagrant reload --provision. After that when you use secure shell - vagrant ssh you should be able to run npm install from inside you project directory.
Related
I created a Node app that relies on a dependency (Jest) that is just for running tests.
I want to zip this app up and run it and its tests on another machine that has node installed.
My package.json includes
"scripts": {
"test": "jest"
},
and jest is included in the app's npm_modules folder.
The tests work perfectly on the machine that the app was developed on. However, upon extracting the zip and running on another computer, I get an error that jest is not found.
I then reinstalled jest without '--save-dev' and installed it for production use, thinking this would resolve the error, but it did not.
I thought the point of having npm_modules and using 'npm install' was so that the app's dependencies can all be localized and portable i.e. not having host machine have to install modules separately.
Is there any way to resolve this? Thanks!
According to "scripts": { "test": "jest" }, you have jest installed globally on source machine. Change it to "scripts": { "test": "node_modules/.bin/jest" },
Try using pkg
Github Page
npm
If you just need to run it on the second machine, pkg should let you package it as a standalone executable.
I'm guessing the problem is either that Jest installs differently based on the OS. It may also be a problem with import-local, one of the packages that Jest depends on.
I am struggling with the error:
Uncaught Exception:
Error: A dynamic link library (DLL) initialization routine failed."
After some research and debugging, the likely issue is that the node module ffi has not been "rebuilt" for the electron environment. I have tried following the steps at https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md to rebuild the package, but method 1, when copied to the letter, didn't work.
Method 2 of "Installing module and rebuilding for Electron" doesn't work because entering ./node_modules/.bin/electron-rebuild.cmd (I'm on Windows) doesn't work- Bash simply says "command not found" and I don't see others with this issue. I've tried even running it from PowerShell in case git bash was causing issues, but I get a similar issue, although I also get an error stating:
At line:1 char:1
+electron-rebuild.cmd
+~~~~~~~~~~~~~~~~~~~
_CategoryInfo : ObjectNotFound: (electron-rebuild.cmd:String) [], CommandNotFoundException
+FullyQualifiedErrorID : CommandNotFoundException
I don't understand method 3 (manually building for Electron) and am hesitant to use it- namely I'm unsure of why there isn't an argument in the manual build command for specifying what package needs to be rebuilt.
I have retried installing Electron Rebuild to the letter per the instructions in https://github.com/electron/electron-rebuild multiple times (npm install --save-dev electron-rebuild) in project folder. It seems to be installed in the correct location.
Why is electron-rebuild not being recognized? What will it take to get ffi installed properly?
I'd also appreciate if someone could point me to some additional places to educate myself on what I might be missing with my conceptualization of this issue. Thanks in advance!
Ok, this works for me:
Ensure Python 2.7.X is installed.
Get and Install Visual Studio Build Tools (eg. http://landinghub.visualstudio.com/visual-cpp-build-tools )
To use the correct msvs version during rebuild enter this in eg. a powershell: npm config set msvs_version 2015 --global
In my minimal example I used the following package.json:
{
"name": "stack_ffi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"rebuild": "electron-rebuild -f -w ffi"
},
"author": "",
"license": "XXX",
"devDependencies": {
"electron": "2.0.2",
"electron-rebuild": "1.7.3"
},
"dependencies": {
"ffi": "2.2.0",
"ref": "1.3.5"
}
}
Run npm run install and then npm run rebuild
Notes:
On my first try electron did not install correctly so I have deleted
the ./node_modules/electron folder and ran npm run install again.
When I tried to use a sqlite3.dll on Windows the online example (https://github.com/node-ffi/node-ffi/blob/master/example/sqlite.js) did
not work. I had to remove the leading "lib" part from the library string: var SQLite3 = ffi.Library('sqlite3', {...}); //was 'libsqlite3'.
I tested it on node 7.4.0 and 8.0.0. If it fails on your node version
I have the theory that v8::Object::ForceSet was dropped on later
versions.
I had to ensure that Windows can find my dll's. For example I
included the sqlite3 x64 dlls by adding their folder
location to the PATH env variable.
Look out your python version, ffi only support python 2x because of node-gyp only support python 2x.
Try to uninstall python 3x and reinstall python 2x.
I am working on a project and I want to use JSdoc for documentation. I have listed it in devDependencies and created a script to run it. My package.jsonlooks like:
"scripts": {
"doc": "jsdoc -c ./conf.json"
},
"devDependencies": {
"jsdoc": "^3.4.3"
}
Cloning my project on another machine and typing npm install installs jsdoc to the node_modules folder.
However, when I run npm run doc, I get a large error, the center of which is: 'jsdoc' is not recognized as an internal or external command
This is because JSdoc is installed in node_modules not my local path.
What is the best way to point npm-run commands to my locally installed modules? Also, what is the point of having dependencies such as JSdoc listed in devDependencies (thus installed in node_modules) when they can not be used from there?
Based on this question, when I try to run the suggested answer (heroku run npm run "script name") I get "bash: npm: command not found". I'm trying to trigger the script on a deployed meteor NodeJS app to Heroku (node version 4.8.2 and npm version 4.6.1). Any solutions to why?
package.json
{
"name": "admini_meteor",
"private": true,
"scripts": {
"deploy": "MONGO_URL=mongodb://52.1.130.211/cloud meteor"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"bcrypt": "^1.0.2"
}
}
Procfile
web: npm run deploy
You need to add nodejs in your buildpack
And then deploy your app again! That's all!
I am no expert but I will try to give you a hint of your problem because I had the same one. Everything is in the docs you just need to read it.
So far the web process in the one taking care of running the actual app/server like here.
But also how is your project structure? Heroku detects you are developing a node project (because of package.json file in root directory) so it should install npm for you.
In my case I was developing a Laravel app, therefore, it created a PHP application without node and npm. There is a way to tell heroku you need both environments like state here
My package.json includes webpack and some loaders:
"devDependencies": {
"babel-core": "^5.2.17",
"babel-loader": "^5.0.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "^0.5.0",
"webpack": "^1.9.4"
}
When I run webpack it's not in my path so it doesn't show as found. I installed it globally npm install -g webpack so the binary would appear in my path, but then it can't find the loader modules that were installed in ./node_modules that it needs to process my dependency tree:
$ webpack --progress --colors --watch
10% 0/1 build modules/usr/local/lib/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:206
throw e;
^
Error: Cannot find module 'jstransform/simple'```
What is the preferred solution here?
I can install my loaders globally, but I don't like that because of cross-project issues
I can try to run webpack out of node_modules (not sure how to be honest, add it to $PATH for every project?)
Or I can try to give my global webpack access to my node_modules folder, which also seems hacky.
Have I done something wrong, or is there a better community-approved way around this maybe common problem?
I have a blog post called Managing Per-Project Interpreters and the PATH that details my methodology for this. I'll summarize here to address some of your key questions.
What is the preferred solution here?
Never (really, literally never) use npm -g. Just install normally within your project. Use your shell to set the PATH appropriately. I use zsh to do this automatically as detailed in the blog post above so if I cd into a project with ./node_modules/.bin, it gets put on my PATH automatically.
There are other ways that work including making aliases like alias webpack="./node_modules/.bin/webpack" and so on. But really just embrace changing your PATH and you'll have the most harmonious long-term experience. The needs of a multiproject developer are not met by old school unix everything lives in either /bin or /usr/bin.
If you use npm scripts (the "scripts" key in your package.json), npm automatically includes ./node_modules/.bin in your PATH during those scripts so you can just run commands and they will be found. So make use of npm scripts and if you make use of shell scripts that's an easy place to just do export PATH="$PWD/node_modules/.bin:$PATH".
Any binaries that come with packages defined in your dependencies should be placed under ./node_modules/.bin, so you should be able to access there, i.e.: ./node_modules/.bin/webpack.
Alternatively, you could define a script inside your package.json, which would allow you to run something like npm run webpack as an alias.