Error "Cannot find module 'errors.server.controller.js'" while trying to extend default backend - mean-stack

I want to add new code to my backend, which will put some data to MongoDB collection. I decided to do it in core.server.controller.js because my app will be really simple and I don't need to create a new module for this. So I opened /app/controllers/users/users.profile.server.controller.js, a mean.js built-in controller and copied
var _ = require('lodash'),
errorHandler = require('../errors.server.controller.js'),
mongoose = require('mongoose'),
passport = require('passport'),
User = mongoose.model('User');
to core.server.controller.js file to provide mongoose and the other stuff. Then I removed ../ from errorHandler require argument and changed mongoose model name to my own, which I've created before.
But when I want to start this app in console, I get an error:
Error: Cannot find module 'errors.server.controller.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/developer2/baca/app/controllers/core.server.controller.js:7:17)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at module.exports (/Users/developer2/baca/app/routes/core.server.routes.js:5:13)
at /Users/developer2/baca/config/express.js:118:35
at Array.forEach (native)
at module.exports (/Users/developer2/baca/config/express.js:117:49)
at Object.<anonymous> (/Users/developer2/baca/server.js:24:38)
So how can I fix this?

You are requiring errors.server.controller.js however the path is wrong.
You can either use the file path relative to your app root directory or to the file (core.server.controller.js) from where you're requiring:
Solution 1: Path relative to the app root directory (preferred for the sake of consistency since MEAN.js uses path for requires in other js files):
You can use node path module to help you with this like so:
var path = require('path),
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller.js'));
Note that the file path is relative to the root directory of your app and path module will handle that for you.
Solution 2: Path relative to the current file:
Since they are both in the same directory:
var errorHandler = require('./errors.server.controller.js');

Related

Cannot find module 'fs-extra' error when launching tests despite the module is present in cypress

Just encountered the issue. After launching my tests this error appears in the cypress context window.
Can't start server
The plugins file is missing or invalid.
Your pluginsFile is set to /Users/alexanderti/WebstormProjects/klickly-autotests-js/cypress/plugins/index.js, but either the file is missing, it contains a syntax error, or threw an error when required. The pluginsFile must be a .js or .coffee file.
Please fix this, or set pluginsFile to false if a plugins file is not necessary for your project.
Error: Cannot find module 'fs-extra'
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:473:25)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/alexanderti/WebstormProjects/klickly-autotests-js/cypress/plugins/index.js:51:12)
at Object.<anonymous> (/Users/alexanderti/WebstormProjects/klickly-autotests-js/cypress/plugins/index.js:165:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at module.exports (/Users/alexanderti/Library/Caches/Cypress/3.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:118:15)
at Object.<anonymous> (/Users/alexanderti/Library/Caches/Cypress/3.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js:9:25)
at Object.<anonymous> (/Users/alexanderti/Library/Caches/Cypress/3.4.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/index.js:11:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (module.js:683:10)
at startup (bootstrap_node.js:196:16)
at bootstrap_node.js:622:3
Everything worked fine until I accidentally installed fs-exta module in package.json via UI prompt in Webstorm and then uninstalled it. Also removed ./node_modules and installed back.
But the error remains.
I've checked modules availability via npm ls fs-extra and it shows that it present
─┬ cypress#3.4.0
│ └── fs-extra#5.0.0
├─┬ mochawesome-merge#2.1.0
│ └── fs-extra#7.0.1
└─┬ mochawesome-report-generator#4.1.0
└── fs-extra#7.0.1
Just add this to your package.json:
"browser": {
"fs": false
}
solved the problem for me. I also added two more to avoid more problems:
"browser": {
"fs": false,
"path": false,
"os": false
}
Fixed by re-installing node_modules directory but with package-lock.json deleted, perhaps because of this it was looking on old version. Now fixed
is that sort of solution ?
https://github.com/cypress-io/cypress/issues/21615#issuecomment-1170103810
step 1
delete the caches
step 2
reinstall cypress
and I got the old version successfully

Rxjs Mocha tests will not run on WebStorm

I have been trying to get the spec tests running from the rxjs repository on the WebStorm IDE.
https://github.com/ReactiveX/rxjs.git
The issue is that I can run the tests using the included script, and manually through the command line but configuring WebStorm is not working.
Below is the error message that I am getting most frequently. I have included the default opts file for Mocha, and below is the result.
ReferenceError: asDiagram is not defined
at Suite.<anonymous> (/Users/test/Desktop/Test/rxjs/spec/Observable-spec.ts:636:3)
at Object.create (/Users/test/Desktop/Test/rxjs/node_modules/mocha/lib/interfaces/common.js:112:19)
at context.describe.context.context (/Users/test/Desktop/Test/rxjs/node_modules/mocha/lib/interfaces/bdd.js:44:27)
at Object.<anonymous> (/Users/test/Desktop/Test/rxjs/spec/Observable-spec.ts:635:1)
at Module._compile (module.js:652:30)
at Module.m._compile (/Users/test/Desktop/Test/rxjs/node_modules/ts-node/src/index.ts:430:23)
at Module._extensions..js (module.js:663:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/test/Desktop/Test/rxjs/node_modules/ts-node/src/index.ts:433:12)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
the problem occurs because Webstorm is passing --ui bdd to mocha, overwriting your custom ui specified in spec/support/default.opts. To work out the issue, you have to change User interface: option in Mocha run configuration from default (bdd) to your custom one (spec/helpers/testScheduler-ui.ts) - field is editable, you can type/paste the value. Configuration that works fine for me:

SyntaxError: Unexpected token =>

When I ran the gulp command from the root of the project, a problem turned out.
elixir((mix) => {
SyntaxError: Unexpected token =>
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at execute (D:\nodejs\node_global\node_modules\gulp-cli\lib\versioned\^3.7.0\index.js:24:18)
at Liftoff.handleArguments (D:\nodejs\node_global\node_modules\gulp-cli\index.js:149:63)
at Liftoff.<anonymous> (D:\nodejs\node_global\node_modules\gulp-cli\node_modules\liftoff\index.js:198:16)
The gulpfile is from a Laravel Project, here it is https://github.com/rappasoft/laravel-5-boilerplate/blob/master/gulpfile.js .
I had searched the problem above over stack and other network station, but couldn't find any useful advise.
Btw, it was run on Windows, you can get it from the details code above.
If somebody can help, I will be very appreciate . THX !
Arrow function are new JavaScript (ES6), so maybe your node and npm version is old and you should upgrade it. Use this official installer.
https://nodejs.org/dist/v6.9.2/node-v6.9.2-x64.msi

How can I run script files by their shortcuts in Windows?

Tried naive way with a standard Windows shortcut file and with a cmd.exe, failed like this:
D:\...>node tty-checker.js.lnk
D:\...\tty-checker.js.lnk:1
(function (exports, require, module, __filename, __dirname) { L
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
Maybe you can suggest a way?
Amazing if there is a general method working not only for .js, but for any other source code file type too.

Can't run Google Coder on Mac

I'm trying to run Google Coder on Mac following the following instructions:
http://pi.gadgetoid.com/article/running-google-coder-on-your-existing-raspberry-pi-or-desktop-pc
Everything goes well until I have to launch the server. This is what I get:
node server.js
module.js:340
throw err;
^
Error: Cannot find module '/Users/sebasribas/Downloads/coder-master/coder-base/apps/auth/app'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at pingStatusServer (/Users/sebasribas/Downloads/coder-master/coder-base/server.js:187:23)
at Object.<anonymous> (/Users/sebasribas/Downloads/coder-master/coder-base/server.js:278:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Any suggestion?
Thanks a lot for your help.
Found this here: https://github.com/googlecreativelab/coder/issues/56
You'll need to install the relevant apps before it'll work.
cd ~/coder-dist/coder-apps/
Install the base apps that are common to all platforms:
./install_common.sh ../coder-base/
This copies the common platform apps to the coder-base working directory.
By looking at your error log you're missing a module. Did you run 'npm install' in the coder-base directory after downloading it?
A little tedious, I'm sure there's a more automated way, but...
Follow the robot instructions in coder-apps/install_app.sh
Basically, you copy the app directories from coder-apps/common into three places:
coder-base/apps
coder-base/static
coder-base/views
So that in each of these directories there is a folder per-app.
Then, copy the contents of those app's respective 'app', 'static', and 'views' folders into the root of the application directory.
For example- in coder-base/apps, for the "auth" app, I copied /app/app.js and /app/meta.json into the root level of the directory that I just created: coder-base/apps/auth.
You don't have to copy all the sample apps, but you definitely need at least the auth, editor, boilerplate, and coderlib.
I'd just copy them all to be safe!
Have fun hacking :)

Resources