I'm trying to install the Now.js module for Node.js. It gets installed, but it doesn't work. When I install it, here's what I get:
eustace#eustace-desktop:/var/www/nowjs$ sudo npm install now -g
> node-proxy#0.5.1 install /usr/local/lib/node_modules/now/node_modules/node-proxy
> make
BUILDING: C++ Component
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.038s)
Waf: Entering directory `/usr/local/lib/node_modules/now/node_modules/node-proxy/src/build'
[1/2] cxx: node-proxy.cc -> build/default/node-proxy_1.o
[2/2] cxx_link: build/default/node-proxy_1.o -> build/default/node-proxy.node
Waf: Leaving directory `/usr/local/lib/node_modules/now/node_modules/node-proxy/src/build'
'build' finished successfully (0.909s)
now#0.7.4 /usr/local/lib/node_modules/now
├── node-proxy#0.5.1
└── socket.io#0.8.2
I'm trying to get the example working (http://nowjs.com/doc/example), but when I run helloworld_server.js in terminal, here's what I get:
eustace#eustace-desktop:/var/www/nowjs$ node helloworld_server.s
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '/var/www/nowjs/helloworld_server.s'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
eustace#eustace-desktop:/var/www/nowjs$ node helloworld_server.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'now'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at require (module.js:346:19)
at Object.<anonymous> (/var/www/nowjs/helloworld_server.js:7:13)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
I'm using Node.js v0.4.11 and Ubuntu 11.04. I tried doing 'export NODE_PATH="/usr/local/lib/node"', but it didn't help.
How do I fix this?
The problem was that I mistyped helloworld_server.js. I wasted around 6 hours trying to fix this, what a stupid mistake :)
Related
I am trying to run some simple commands using child_process.exec. But in some odd corner cases, it tries to execute the given command with node, rather than the given (or default) shell.
Results
E.g., given below code, I get the following results:
cmd
Result
❌
'"yarn" -v'
Cannot find module 'C:\cwd\yarn.js'
❌
'"npm" -v'
Cannot find module 'C:\cwd\node_modules\npm\bin\npm-cli.js'
✅
'yarn -v'
(works as expected)
✅
'"C:\path\to\yarn" -v'
(works as expected)
OS: Win10
Node: v16., v17. (tried several of them)
EDIT: This seems to be a cmd-specific problem. If I set processOptions.shell = 'bash', it does not occur.
Full Error Message
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\cwd\yarn.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Done - code 1 signal null
Thoughts
It appears that there is a special logic that is triggered, iff the "executable" is in double quotes, and has no spaces or path separators in them...?
Not sure if feature or bug?
Code
// test.js
const cp = require('child_process');
const cmd = '"yarn" install';
const child = cp.exec(cmd);
// ###########################################################################
// process monitoring
// ###########################################################################
child.on('exit', (code, signal) => {
console.log('Done - code', code, ' signal', signal);
});
child.on('error', (err) => {
console.error(`Error:`, err);
});
// inherit stdio
child.stdout.pipe(process.stdout);
process.stdin.pipe(child.stdin);
child.stderr.pipe(process.stderr);
Turns out, it is a volta bug. I filed it here.
Easy to verify: Change the command to do other things on top of "yarn" install. The following still shows hi, but the yarn part still bugs out, so it is definitely not an issue with node or cmd:
const cmd = 'echo "hi" && "yarn" install';
const child = cp.exec(cmd);
Some more explanation: volta manages node, npm and yarn for you, making it very easy to install/uninstall/pin versions globally or even per folder/project. That means that "yarn" install does not actually run yarn, but actually this:
Runs a volta executable
Which will then run yarn...
...which evidently messed up the logic to look up the actual executable.
This happens only with yarn and npm. Everything else (thus far) seems fine, including node itself.
I'm encountering some trouble running Gridsome build on a starter project template. The site runs on localhost with no problem. I tried npm install gridsome#latest to update or install any missing packages.
Gridsome build gives me the following error:
Could not generate HTML for "/work/":
TypeError: Cannot read property 'console' of null
at Object. (C:\Users\Micah\Desktop\my-gridsome-site\node_modules\vue-meta\dist\vue-meta.common.js:103:23)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Users\Micah\Desktop\my-gridsome-site\node_modules\vue-server-renderer\build.prod.js:1:77671
at Object. (webpack:/external "vue-meta":1:0)
The code at vue-meta.common.js:103:23 reads var console = _global.console || {}; as shown below:
var hasGlobalWindow = hasGlobalWindowFn();
var _global = hasGlobalWindow ? window : global;
var console = _global.console || {};
function warn(str) {
/* istanbul ignore next */
if (!console || !console.warn) {
return;
}
console.warn(str);
}
var showWarningNotSupported = function showWarningNotSupported() {
return warn('This vue app/component has no vue-meta configuration');
};
Steps to reproduce
Run gridsome build from command line.
Environment
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-4210U CPU # 1.70GHz
Binaries:
Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.18362.449.0
npmPackages:
gridsome: ^0.7.11 => 0.7.11
gridsome-plugin-tailwindcss: ^2.2.26 => 2.2.26
I think the problem is only in build because of lack of SSR (server side rendering) of your component. There is no window in build mode. Try to wrap your component inside vue's <template> tag with <ClientOnly> tag like this:
<template>
<ClientOnly>
<my-component />
</ClientOnly>
</template>
I have a node.js function which uses fs.access to check if a file exists, is readable and writable:
function StackOverFlowFunction() {
try {
fs.accessSync(`file://${__dirname}/config/config.ini`, fs.constants.F_OK | fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {
console.log(err);
}
despite the file EXISTING,
{ Error: ENOENT: no such file or directory, access 'file:///home/callcenter1/BookGenerator/config/config.ini'
at Error (native)
at Object.fs.accessSync (fs.js:248:11)
at Object.fs.accessSync (ELECTRON_ASAR.js:420:27)
at getConfig (/home/callcenter1/BookGenerator/main.js:12:12)
at Object.<anonymous> (/home/callcenter1/BookGenerator/main.js:18:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
errno: -2,
code: 'ENOENT',
syscall: 'access',
path: 'file:///home/callcenter1/BookGenerator/config/config.ini' }
I used the "Open Link" function from the Ubuntu terminal and it opened the file with gedit successfully.
What's the issue?
Edit 1:
I'm almost sure the path is right:
Use a proper filesystem path, without a scheme:
fs.accessSync(`${__dirname}/config/config.ini`, ...)
I faced similar error message due to completely different reason. If you set path based on some env variables, this can happen because an extra (space) added to the variable value on Windows. Then the message will look quite obscure, like an existing file you sure about does not exist:
{ "errorMessage":"The file at x:\\path\\to\\file.ext does not exist, or it is not a file. ENOENT: no such file or directory, lstat 'x:\\path\\to\\file.ext '" }
Notice the (double space) between file.ext and does.
I used syntax like
SET "VARIABLE_NAME=VALUE-WHERE-EXTRA-SPACE-CAUSES-ERROR";
to fix the issue. Found that here: https://superuser.com/a/1290292
I am just learning Unit.js with mocha. I am following the steps at: http://unitjs.com/guide/quickstart.html . I have installed mocha and am running the "example.js" script. The script fails with
$ mocha example.js
0 passing (1ms)
Running the example.js in with -full-trace I get:
$ mocha example.js -full-trace
C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\lib\utils.js:652
throw new Error("cannot resolve path (or pattern) '" + path + "'");
^
Error: cannot resolve path (or pattern) '-t'
at Object.lookupFiles (C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\lib\utils.js:652:15)
at C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:326:30
at Array.forEach (native)
at Object.<anonymous> (C:\Users\rball\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:325:6)
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)
at startup (node.js:134:18)
at node.js:961:3
I am running this with cygwin64. and running in the directory: /home/rball/test
the example.js is:
// load Unit.js module
var test = require('../node_modules/unit.js');
// just for example of tested value
var example = 'hello';
// assert that example variable is a string
test.string(example);
// or with Must.js
test.must(example).be.a.string();
// or with assert
The unit.js is in the node_modules directory.
The error in the full trace output is baffling since I am not aware of any path with a "-t" in it.
What am I missing?
Thanks for your help
I think you need an extra '-' in front of '-full-trace'.
Example: '--full-trace'
You set your asserter with 'test.string(example)'. You've already passed it the specified variable type, which would be fine if you were validating the string value, length, etc.
Try this instead:
'test.value(example).isString();'
----or----
'test.value(example).must.be.a.string();'
http://unitjs.com/api/value.html#isString
I'm trying to install NPM.
I first ran
brew install node
then
curl -O https://www.npmjs.org/install.sh
then
~ % sh install.sh
this is what I get
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm#latest
fetching: http://registry.npmjs.org/npm/-/npm-2.0.2.tgz
/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:18
val = val[f]
^
TypeError: Cannot read property 'node' of undefined
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:18:16
at Array.forEach (native)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:17:11
at Array.forEach (native)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:14:22
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:51:40
at final (/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:349:17)
at then (/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:126:33)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:266:40
at evalmachine.<anonymous>:271:14
0.10.32
/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:18
val = val[f]
^
TypeError: Cannot read property 'node' of undefined
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:18:16
at Array.forEach (native)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:17:11
at Array.forEach (native)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/bin/read-package-json.js:14:22
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:51:40
at final (/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:349:17)
at then (/private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:126:33)
at /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package/node_modules/read-package-json/read-json.js:266:40
at evalmachine.<anonymous>:271:14
> npm#2.0.2 prepublish /private/var/folders/92/2l_j234x7n7bys14466b4dcr0000gn/T/npm.12852/package
> node bin/npm-cli.js prune --prefix=. --no-global && rm -rf test/*/*/node_modules && make -j8 doc
make: Nothing to be done for `doc'.
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm#2.0.2 /usr/local/lib/node_modules/npm
It worked
I know it says it worked... I'm just trying to find out what the error message means. And see what I can do to fix it.
Any ideas?
Thanks for the help!
Although it looks like you got this all sorted out, I would like to answer this to put forward the "official" (npm-supported) way of installing npm on OSX:
don't use brew;
install the "official" node binary from https://nodejs.org/download
install the latest npm : sudo npm install -g npm#latest
If you install it that way, it is easier to get support on the npm issue tracker at https://github.com/npm/npm