Node & Brunch & PIXI.js on Windows, module "querystring" not found - node.js

I'm having troubles setting up a PIXI project on my Windows machine.
It's very easy to reproduce:
npm install -g brunch
brunch new .
npm install --save-dev pixi.js
Then insert require("pixi.js") somewhere (e.g. initialize.js), and
npm run start
Open localhost:3333 and there's the following error:
Uncaught Error: Cannot find module 'querystring' from 'url/url.js'
at require (app.js:61)
at expanded (app.js:34)
at app.js:147
at url.js:104
at url.js:737
at initModule (app.js:42)
at require (app.js:59)
at expanded (app.js:34)
at app.js:147
at determineCrossOrigin.js:10
It works perfectly on a Linux machine (debian), but I always get this error on my Windows machine.
$ node -v
v6.9.5
$ npm -v
4.2.0
$ systeminfo | grep "OS"
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.14393 N/A Build 14393
The troubling module is pixi. If I install and require any other module, it works fine. It also doesn't work if I install the querystring explicitly (npm install querystring), although it's a built-in module.
Any ideas?

I've got it resolved by using bower. It's a workaround though.
npm install -g bower
bower install --save pixi.js
Then the PIXI object will be available globally out of the box. Just use it in your code.

Related

Installed ES Lint globally but getting error -bash: eslint: command not found

I am on a mac using Catalina.
I installed ES Lint globally using
npm install -g eslint
the output says
/usr/local/opt/nvm/versions/node/v10.13.0/bin/eslint -> /usr/local/opt/nvm/versions/node/v10.13.0/lib/node_modules/eslint/bin/eslint.js
+ eslint#7.10.0
However I am confused because I made sure to use nvm uninstall node v10.13.0. Then I downloaded the latest install from the node website and installed it.
when I do node -v I get
v12.18.4
Why is it still installing ESlint it to the old 10.13.0 directory?

Installing Ionic - The term 'ionic' is not recognized

I am having trouble installing node.js and npm on my computer. I am running Windows 10 Pro x64, and using Windows Powershell (admin).
I am running node.js 9.10.1 and npm 5.8.0
Here's a screenshot of the error:
As you can see from the screenshot, I installed ionic cordova using the npm install -g ionic cordova command. (I don't know what the difference between that and npm install -g ionic is, though.)
I tried changing the windows PATH -thing, but I'm not sure if I did it correctly. (In the path-environment-variable I added a path to 'C:\Users\Peter\AppData\Local\npm' and one to 'Z:\Program\nodejs' where I installed node.js.)
Try using Roaming instead of Local. I think that installing with -g should go in Roaming.
C:\Users\Peter\AppData\Roaming\npm>

node-serialport does not work with Electron

My task is to build a HTML5 desktop app, which works with serial port, because I have an arduino on the other side on COM-port.
I installed electron-prebuilt and serialport packages both (I specified them in package.json).
In my main web page I included main.js, and there I tried to require the serialport package, but I got the following error:
Uncaught Error: Cannot find module
'D:\Projects\arduino\HTMLPresentation\node_modules\serialport\build\serialport\v1.7.4\Release\node-v45-win32-x64\serialport.node'
I've read some QA topics about that problem (some abracadabras with node-gyp), but noting works for me: on both windows 8.1 and Ubuntu 15.04. I don't know how to adopt serialport package for electron.
My enviroment:
Vue.js: 2.6.10
Electron: 2.0.18
Node: 8.9.3
Platform: linux
If you are using Eletron with Vue.js you need to rebuild the serialport module doing something like this:
npm install electron-rebuild --save-dev
after this, you can add in your package.json > section "scripts", another line saying:
"rebuild": "electron-rebuild -f -w serialport"
You can rebuild the module with terminal command
npm run rebuild
Now the serialport module should be imported and will work as expected. Goog luck!
Use Electron-Rebuild: This executable rebuilds native io.js modules against the version of io.js that your Electron project is using. This allows you to use native io.js modules in Electron apps without your system version of io.js matching exactly.
npm install --save-dev electron-rebuild
# Every time you run "npm install", run this
./node_modules/.bin/electron-rebuild
# On Windows if you have trouble, try:
.\node_modules\.bin\electron-rebuild.cmd
This is how you would solve it
Install windows build tools in your computer by running this in your powershell with administrator access
npm install --global --production windows-build-tools
or npm --add-python-to-path='true' --debug install --global windows-build-tools
setx PYTHON "%USERPROFILE%\.windows-build-tools/python27/python.exe"
set PYTHON
set PYTHON helps you check if its set up correctly.
This is not enough install electron rebuild globally in your project files
npm install -g electron-prebuilt
npm install --save serialport
We have to rebuild serialport to work with electron. To do this, we need to >install electron-rebuild:
npm install --save-dev electron-rebuild
The last step is to run electron-rebuild, once again, just in the root >directory of the app:
./node_modules/.bin/electron-rebuild
import and use in your electron-vue project
<script>
const sp = require('serialport')
export default {
name: 'landing-page',
methods: {},
created () {
sp.list(function (error, ports) {
if (error) {
console.log(error)
} else {
console.log(ports)
}
})
}
}
</script>

npm module Imager installation

I have been trying to install npm package because for some odd reason the module and GraphicsMagick library vanished into thin air from my machine(but that is a discussion for some other day).
Now I have installed the library but when I run
sudo npm install --save imager
I get a long list of errors. starting from
Error: ENOENT, lstat '/home/user/Desktop/project/node_modules/imager/node_modules/pkgcloud/node_modules/request/node_modules/json-stringify-safe/LICENSE'
any help would be appreciated.
Many npm modules are skins over previously written native code projects.
In this case : GraphicsMagick
If you first do the install of GraphicsMagick (outside of node/npm) or whichever is the underlying project. Get it up and running and only then do the npm install of its skin it will work. I just did these steps on ubuntu for npm module imager and the install worked fine.
Understand the meaning of npm install with a -g flag (global) - If the module makes available a command line executable then do npm install -g xxxx

Node Version Manager (NVM) npm installing modules to common folder

I've installed NVM for node.js using the instructions from this post:
http://www.backdrifter.com/2011/02/18/using-nvm-and-npm-to-manage-node-js/
When I switch between node versions and then use npm to install a module, all the modules are placed in the same 'node_modules' folder (~/node_modules/) instead of in the 'node_modules' directory specific to that version of node?
Any idea on how to remedy this?
Based on the comments from https://github.com/creationix/nvm/pull/97:
When installing packages with npm using the global switch -g the
package ends up in the proper directory (i.e.
.nvm/$VERSION/lib/node_modules), however node is unable to require it
since it somehow isn't searching on it's prefix.
So using npm install -g xxxxx will put the modules in the correct location for NVM but if you try to require one of them node can't find the module. I am still playing around with this and will update if I find a solution.
Update
Where does NPM put node_modules? (see https://docs.npmjs.com/files/folders)
Local install (default): puts stuff in ./node_modules of the current package root.
Global install (with -g): puts stuff in /usr/local or wherever node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use npm link.
So what I did was run npm init (see http://npmjs.org/doc/init.html) in my projects root dir which generated package.json. Now when I run npm install xxxxx it creates a node_modules dir in my project folder (which I add to my .gitignore). This works for modules that I require in my code.
For commands such as CoffeeScript I install with npm install -g coffee-script which puts it in the correct directory (.nvm/$VERSION/lib/node_modules). While I can't require these modules (npm link should solve this problem) I can run the commands - i.e. coffee.
I just installed express globally (-g) and was having problem when require("express"). Just like Jesse Vogt said I just reinstalled express but this time without the -g just like this: "sudo npm install express" and now is working perfectly!
For latest nvm window version 1.1.7.
Package was installed and placed into the respective nodejs version.
nvm use 16.8.0
npm install truffle
nvm use 16.7.0
npm install mysql

Resources