Can't Find Locally Installed Module in Windows - node.js

I've got a very simple script that I'm using to test this scenario, but I can't figure out why Node wouldn't be able load the module that's locally installed.
package.json:
{
"name": "Test",
"version": "1.0.0",
"dependencies": {
"cli-progress-bar": "^0.1.0"
}
}
Test.js:
var ProgressBar = require("cli-progress-bar"),
progress = new ProgressBar(),
processed = 0;
function update () {
if (processed < 100) {
progress.show(++processed / 100);
setTimeout(update, 750);
}
}
update();
As far as I can tell, this should just load the cli-progress-bar package, and run a simple progress bar to completion before exiting.
This is the output I get when I try to install the dependencies and run the script:
C:\Users\Benjamin\Desktop\Test>node -v
v4.2.1
C:\Users\Benjamin\Desktop\Test>npm -v
3.3.10
C:\Users\Benjamin\Desktop\Test>npm install
Test#1.0.0 C:\Users\Benjamin\Desktop\Test
└─┬ cli-progress-bar#0.1.0
├── cli-character-set#0.1.0
├─┬ lodash.padleft#3.1.1
│ ├── lodash._basetostring#3.0.1
│ └─┬ lodash._createpadding#3.6.1
│ └── lodash.repeat#3.0.1
├── lodash.padright#3.1.1
└─┬ log-update#1.0.2
├── ansi-escapes#1.1.0
└─┬ cli-cursor#1.0.2
└─┬ restore-cursor#1.0.1
├── exit-hook#1.1.1
└── onetime#1.0.0
npm WARN EPACKAGEJSON Test#1.0.0 No description
npm WARN EPACKAGEJSON Test#1.0.0 No repository field.
npm WARN EPACKAGEJSON Test#1.0.0 No license field.
C:\Users\Benjamin\Desktop\Test>node Test.js
module.js:339
throw err;
^
Error: Cannot find module 'cli-progress-bar'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (C:\Users\Benjamin\Desktop\Test\Test.js:1:81)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
I can see that the the package is installed in C:\Users\Benjamin\Desktop\Test\node_modules but I can't seem to use it.
C:\Users\Benjamin\Desktop\Test>dir node_modules
Volume in drive C is OS
Volume Serial Number is 7294-620F
Directory of C:\Users\Benjamin\Desktop\Test\node_modules
11/02/2015 10:00 AM <DIR> .
11/02/2015 10:00 AM <DIR> ..
11/02/2015 10:00 AM <DIR> ansi-escapes
11/02/2015 10:00 AM <DIR> cli-character-set
11/02/2015 10:00 AM <DIR> cli-cursor
11/02/2015 10:00 AM <DIR> cli-progress-bar
11/02/2015 10:00 AM <DIR> exit-hook
11/02/2015 10:00 AM <DIR> lodash.padleft
11/02/2015 10:00 AM <DIR> lodash.padright
11/02/2015 10:00 AM <DIR> lodash.repeat
11/02/2015 10:00 AM <DIR> lodash._basetostring
11/02/2015 10:00 AM <DIR> lodash._createpadding
11/02/2015 10:00 AM <DIR> log-update
11/02/2015 10:00 AM <DIR> onetime
11/02/2015 10:00 AM <DIR> restore-cursor
0 File(s) 0 bytes
15 Dir(s) 283,532,754,944 bytes free
C:\Users\Benjamin\Desktop\Test>npm ls
Test#1.0.0 C:\Users\Benjamin\Desktop\Test
└─┬ cli-progress-bar#0.1.0
├── cli-character-set#0.1.0
├─┬ lodash.padleft#3.1.1
│ ├── lodash._basetostring#3.0.1
│ └─┬ lodash._createpadding#3.6.1
│ └── lodash.repeat#3.0.1
├── lodash.padright#3.1.1
└─┬ log-update#1.0.2
├── ansi-escapes#1.1.0
└─┬ cli-cursor#1.0.2
└─┬ restore-cursor#1.0.1
├── exit-hook#1.1.1
└── onetime#1.0.0
Every time I try to run the script, I get the same error.

The reason why you cannot find module called "cli-progress-bar" is because that module is not exposing itself correctly. The package.json file has a property called main which must be set to the name of script being exported from module. If script is called index.js npm will find it however because script is called bar.js and the package.json file is saying the main file is called index.js it is not being exposed properly and cannot be found by require.

Related

SyntaxError: Unexpected identifier 'pipefail'

I am having this issue when I try to deploy NodeJS app (built with NextJS) using pm2. I follow the instruction described here.
My attempt to execute pm2 start command seemed working, as shown by the snippet below.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐ │ id │ name │ mode │ ↺ │ status │ cpu │ memory │ ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤ │ 0 │ experti │ fork │ 0 │ online │ 0% │ 25.7mb │ └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
But when I run pm2 list, the previous execution turned out to be error.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐ │ id │ name │ mode │ ↺ │ status │ cpu │ memory │ ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤ │ 0 │ process │ fork │ 15 │ errored │ 0% │ 0b │ └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
I checked the pm2 logs as described by this answer and it led me to this log:
`
SyntaxError: Unexpected identifier 'pipefail'
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Object.<anonymous> (/home/equitica/.npm/_npx/5f7878ce38f1eb13/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
/home/<username>/.asdf/plugins/nodejs/shims/npm:4
set -o pipefail
^^^^^^^^
`
So, I checked the file that specified by the log, and found this line (shown below):
#! /usr/bin/env bash
set -eu
set -o pipefail <-- this line is probably the problem
I have no idea what the line means, and have no clue to solve the problem.
I solved this issue by removing the /home/<username>/.asdf/plugins/nodejs/shims/npm file and then execute pm2 start npm --name <process> -- run start.

the vue-awesome-swiper dependency was not found

I tried to use swiper plugin on my nuxtjs project. But I've got error on my command line when I running "yarn run dev":
`
yarn run dev
yarn run v1.22.19
$ nuxt
WARN sass-loader#13.1.0 is installed but ^10.1.1 is expected
╭───────────────────────────────────────╮
│ │
│ Nuxt # v2.15.8 │
│ │
│ ▸ Environment: development │
│ ▸ Rendering: server-side │
│ ▸ Target: server │
│ │
│ Listening: http://localhost:3000/ │
│ │
╰───────────────────────────────────────╯
i Preparing project for development
i Initial build may take a while
√ Builder initialized
√ Nuxt files generated
* Client █████████████████████████ building (39%) 245/251 modul
es 6 active
node_modules\setimmediate\setImmediate.js
× Server
Compiled with some errors in 9.04s
× Client
Compiled with some errors in 10.53s
× Server
Compiled with some errors in 9.04s
ERROR Failed to compile with 1 errors
This dependency was not found:
* vue-awesome-swiper/dist/ssr in ./plugins/swiper.js
To install it, you can run: npm install --save vue-awesome-swiper/dist/ssr
i Waiting for file changes
i Memory usage: 143 MB (RSS: 232 MB)
i Listening on: http://localhost:3000/
WARN Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'
`
vue-awesome-swiper does not detected while I've installed by "yarn add vue-awesome-swiper".
And I've followed this instruction on cmd:
npm install --save vue-awesome-swiper/dist/ssr
i Waiting for file changes
i Memory usage: 143 MB (RSS: 232 MB)
i Listening on: http://localhost:3000/
But still have issued on my code. Does anyone have same problems and had solution?

Knex:Error Pool2 - error: password authentication failed for user "username" (Not using UNIX account)

The problem occurs with the following command:
knex --knexfile config/db/knexfile.js migrate:latest
I get the following error:
Knex:warning - Pool2 - Error: Pool was destroyed
Knex:Error Pool2 - error: password authentication failed for user "dennis"
Knex:Error Pool2 - error: password authentication failed for user "dennis"
Error: Pool was destroyed
at Pool._destroyPool (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:560:20)
at Pool.<anonymous> (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:474:18)
at Pool.<anonymous> (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:517:17)
at tryCatcher (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/util.js:16:23)
at Promise.errorAdapter [as _rejectionHandler0] (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/nodeify.js:35:34)
at Promise._settlePromise (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:558:21)
at Promise._settlePromise0 (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:606:10)
at Promise._settlePromises (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:681:18)
at Async._drainQueue (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:148:10)
at Immediate.Async.drainQueues (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)
It seems like it is not using my UNIX account and instead trying to authenticate using username/password.
I have tried the following solutions:
Update pg to the latest
Update knex to the latest
replace the method to trust from:
# IPv4 local connections: host all all 127.0.0.1/32 trust
replace the connection string from [db name] to [postgres://[db name]:
connection: {
database: 'postgres://data-api-dev',
user: '',
password: ''
},
How to I get it to use my UNIX account?
I am on Ubuntu 16.04 using Node v6.3.1.
Here are my installed packages:
├── bluebird#2.10.2
├── body-parser#1.15.2
├── bookshelf#0.10.0
├── chai#3.5.0
├── chai-as-promised#5.3.0
├── colors#1.1.2
├── convict#1.4.0
├── cors#2.7.1
├── express#4.14.0
├── gulp#4.0.0-alpha.2 (git://github.com/gulpjs/gulp.git#d8f5c90a0622d19ef1943a2a3d02dc50e3c853e7)
├── gulp-exit#0.0.2
├── gulp-mocha#2.2.0
├── gulp-nodemon#2.1.0
├── gulp-using#0.1.0
├── jsonwebtoken#5.7.0
├── knex#0.11.10
├── lodash#3.10.1
├── pg#6.1.0
├── request-promise#0.4.3
├── sinon#1.17.5
├── sinon-as-promised#4.0.2
├── sinon-chai#2.8.0
├── supertest#1.2.0
└── validator#4.9.0
Turns out that renaming the method from md5 to trust was the correct solution. I forgot to restart the postgresql service after making the changes, thus it did not work the first time.

Parsoid Server didn't parse pages

Hello:) Got some problems with install of VisualEditor. I have to install Parsoid server and run it. But when I trying to parse some page, I'm getting an error:
TypeError: Cannot read property 'length' of undefined
at peg$c379 (eval at <anonymous> (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:89:38), <anonymous>:1356:61)
at peg$parseeof (eval at <anonymous> (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:89:38), <anonymous>:14738:12)
at peg$parsetlb (eval at <anonymous> (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:89:38), <anonymous>:2007:12)
at peg$parsetoplevelblock (eval at <anonymous> (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:89:38), <anonymous>:1909:12)
at Object.parse (eval at <anonymous> (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:89:38), <anonymous>:17872:18)
at PegTokenizer.tokenizeAsync (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:206:24)
at PegTokenizer._processText (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:180:8)
at PegTokenizer.process (/opt/bitnami/apps/parsoid/lib/mediawiki.tokenizer.peg.js:119:7)
at ParserPipeline.process (/opt/bitnami/apps/parsoid/lib/mediawiki.parser.js:485:21)
at Object.Util.processContentInPipeline (/opt/bitnami/apps/parsoid/lib/mediawiki.Util.js:1112:12)
This is not the same error like this, coz my express and connect versions look fine:
├── alea#0.0.9
├── async#0.9.0
├─┬ bunyan#1.0.1
│ └─┬ mv#2.0.3
│ ├─┬ mkdirp#0.5.0
│ │ └── minimist#0.0.8
│ ├── ncp#0.6.0
│ └── rimraf#2.2.8
├─┬ chai#1.9.2
│ ├── assertion-error#1.0.0
│ └─┬ deep-eql#0.1.3
│ └── type-detect#0.1.1
├── colors#0.6.2
├── diff#1.0.8
├── domino#1.0.18
├── entities#1.1.1
├── es6-shim#0.16.0
├─┬ express#2.5.11
│ ├─┬ connect#1.9.2
│ │ └── formidable#1.0.15
│ ├── mime#1.2.4
│ ├── mkdirp#0.3.0
│ └── qs#0.4.2
.......
I`ve got: NodeJS(v0.10.33), npm(2.1.5) on Ubuntu 14.04.1 LTS
Any ideas?:)
UPDATE:
I just noticed, that I can add new pages with VisualEditor and edit em, also i can edit already existing pages, but if there are no templates. If these pages have templates then there is an error previously described.
There was a problem with version (I got MW 1.23.6 (latest stable)).
I have to update to MediaWiki 1.24 and reinstall VisualEditor (Parsoid already exists in MW >1.24) and then it works fine without errors. Upstart on Ubuntu working well too.

-bash: bower: command not found

I am trying to clone this repo https://github.com/jbroquist/bookingappdemo built on mean stack and after doing npm install and npm install -g bower successfully when i do bower install i get this error
-bash: bower: command not found
When i run the app on the local servers i get these errors in the console
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/bootstrap/dist/css/bootstrap.min.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-strap/dist/angular-strap.tpl.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular/angular.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-route/angular-route.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-animate/angular-animate.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-cookies/angular-cookies.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-motion/dist/angular-motion.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:7000/bower_components/angular-strap/dist/angular-strap.min.js
Uncaught ReferenceError: angular is not defined localhost:7000/app.js:3
Uncaught TypeError: Cannot read property 'factory' of undefined localhost:7000/js/services/config.js:3
Uncaught ReferenceError: angular is not defined localhost:7000/js/services/authentication.js:3
Uncaught ReferenceError: angular is not defined localhost:7000/js/services/eventutil.js:3
Uncaught ReferenceError: angular is not defined localhost:7000/js/services/GoogleCalendarService.js:1
Uncaught TypeError: Cannot read property 'controller' of undefined localhost:7000/js/controllers/MainController.js:3
Uncaught ReferenceError: angular is not defined localhost:7000/js/directives/InputField.js:1
This was the output of running npm install -g bower
/usr/local/bin/bower -> /usr/local/lib/node_modules/bower/bin/bower
bower#1.3.9 /usr/local/lib/node_modules/bower
├── is-root#0.1.0
├── junk#0.3.0
├── stringify-object#0.2.1
├── abbrev#1.0.5
├── chmodr#0.1.0
├── which#1.0.5
├── osenv#0.1.0
├── opn#0.1.2
├── archy#0.0.2
├── graceful-fs#3.0.2
├── rimraf#2.2.8
├── bower-logger#0.2.2
├── bower-endpoint-parser#0.2.2
├── lru-cache#2.5.0
├── lockfile#0.4.3
├── nopt#3.0.1
├── retry#0.6.1
├── tmp#0.0.23
├── q#1.0.1
├── request-progress#0.3.1 (throttleit#0.0.2)
├── shell-quote#1.4.2 (array-filter#0.0.1, array-map#0.0.0, array-reduce#0.0.0, jsonify#0.0.0)
├── chalk#0.5.1 (escape-string-regexp#1.0.1, ansi-styles#1.1.0, supports-color#0.2.0, has-ansi#0.1.0, strip-ansi#0.3.0)
├── semver#2.3.2
├── p-throttler#0.0.1 (q#0.9.7)
├── bower-json#0.4.0 (intersect#0.0.3, deep-extend#0.2.11, graceful-fs#2.0.3)
├── promptly#0.2.0 (read#1.0.5)
├── fstream#0.1.31 (inherits#2.0.1)
├── mkdirp#0.5.0 (minimist#0.0.8)
├── fstream-ignore#0.0.6 (inherits#1.0.0, minimatch#0.2.14)
├── tar#0.1.20 (inherits#2.0.1, block-stream#0.0.7)
├── glob#4.0.5 (once#1.3.0, inherits#2.0.1, minimatch#1.0.0)
├── bower-config#0.5.2 (osenv#0.0.3, graceful-fs#2.0.3, optimist#0.6.1)
├── decompress-zip#0.0.6 (nopt#2.2.1, mkpath#0.1.0, touch#0.0.2, readable-stream#1.1.13, binary#0.3.0)
├── request#2.36.0 (json-stringify-safe#5.0.0, aws-sign2#0.5.0, forever-agent#0.5.2, qs#0.6.6, oauth-sign#0.3.0, tunnel-agent#0.4.0, node-uuid#1.4.1, mime#1.2.11, form-data#0.1.4, http-signature#0.10.0, hawk#1.0.0, tough-cookie#0.12.1)
├── update-notifier#0.2.0 (semver-diff#0.1.0, string-length#0.1.2, latest-version#0.2.0, configstore#0.3.1)
├── bower-registry-client#0.2.1 (graceful-fs#2.0.3, request-replay#0.2.0, lru-cache#2.3.1, async#0.2.10, mkdirp#0.3.5, request#2.27.0)
├── handlebars#1.3.0 (optimist#0.3.7, uglify-js#2.3.6)
├── mout#0.9.1
├── cardinal#0.4.4 (ansicolors#0.2.1, redeyed#0.4.4)
├── inquirer#0.5.1 (readline2#0.1.0, through#2.3.4, mute-stream#0.0.4, chalk#0.4.0, async#0.8.0, lodash#2.4.1, cli-color#0.3.2)
└── insight#0.4.3 (object-assign#1.0.0, async#0.9.0, lodash.debounce#2.4.1, os-name#1.0.0, tough-cookie#0.12.1, request#2.40.0, configstore#0.3.1, inquirer#0.6.0)

Resources