Webstorm UT - cannot find module - javascript

I'm trying to test simple code:
function div2(a, b) {
return a/b;
}
module.exports.div = div2;
And in examplesTestUnit.js file:
var calculator = require("./examples");
module.exports["div test"] = function(test) {
test.equal(calculator.div(6,2), 3);
test.equal(calculator.div(12,0), Infinity);
test.equal(calculator.div(0,3), 0);
test.done();
};
When I try to run test in Webstorm I got errors:
/usr/bin/node /tmp/nodeunit-intellij-starter.js /usr/lib/node_modules/nodeunit examplesTestUnit.js
Testing started at 02:42 ...
module.js:340
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/nodeunit/deps/async'
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 resolveAsyncModule (/tmp/nodeunit-intellij-starter.js:304:20)
at testIt (/tmp/nodeunit-intellij-starter.js:308:21)
at run (/tmp/nodeunit-intellij-starter.js:335:9)
at Object.<anonymous> (/tmp/nodeunit-intellij-starter.js:365:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Process finished with exit code 8
I installed mocha for tests and mocha didnt gives me an errors, but there's still no results:
[DzikiChrzan#DzikiLaptopF untitled]$ mocha examplesTestUnit.js
0 passing (1ms)
[DzikiChrzan#DzikiLaptopF untitled]$
I have installed nodeunit in 0.8.6 version and I already tried to reinstall it.
Plus another error I recive in terminal:
[DzikiChrzan#DzikiLaptopF untitled]$ nodeunit --
/usr/lib/node_modules/nodeunit/lib/nodeunit.js:72
if (err) throw err;
^
Error: ENOENT, stat '/home/DzikiChrzan/WebstormProjects/untitled/--'
I'm using Fedora 22. How can I fix this?

Okay, I did it.
I downloaded and installed nodeunit using npm.
npm install -g n
n stable
Next thing I needed to do was manually indicate path to nodeunit module in WebStorm. In my case it was:
/home/DzikiChrzan/node_modules/nodeunit

Related

NPM is giving me an Error with every command

Whenever I'm running a command with npm. it's giving an Error. A few days ago, It was totally fine. I used it in some of my projects but now it is can't do nothing.
node:internal/modules/cjs/loader:941
const err = new Error(message);
^
Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\utils\\unsupported.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}
The error says that npm can't find the package.json file. Make sure you haven't deleted it. If you want to create one you can use npm init to initialize one in the current directory. Even if that fails I'd reinstall node js and double check the NODE_PATH.

Detox issue: BUILD FAILED Ld build/Build/Products/Debug-iphonesimulator

I'm trying to use Wix/Detox to test my react-native app (the iOS version). I have successfully followed the instructions (up until "detox build") at https://github.com/wix/detox/blob/master/docs/Introduction.GettingStarted.md
However, when running "detox build" in my project directory, I get the following error:
** BUILD FAILED **
The following commands produced analyzer issues:
Analyze RNFIRMessaging.m
(1 command with analyzer issues)
The following build commands failed:
Ld build/Build/Products/Debug-iphonesimulator/<myAppName>.app/<myAppName> normal x86_64
(1 failure)
child_process.js:524
throw err;
^
Error: Command failed: xcodebuild -project ios/<myAppName>.xcodeproj -scheme <myAppName> -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build
at checkExecSyncError (child_process.js:481:13)
at Object.execSync (child_process.js:521:13)
at Object.<anonymous> (/Users/<myUserName>/Documents/react-native-projects/<myAppName>/node_modules/detox/local-cli/detox-build.js:26:6)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
When running "detox test," I get the following error:
node_modules/.bin/mocha e2e --opts e2e/mocha.opts
detox info 09:31:22: server listening on localhost:50342...
detox info 1: Listing devices...
1) "before all" hook
0 passing (376ms)
1 failing
1) "before all" hook:
Error: field CFBundleIdentifier not found inside Info.plist of app binary at /Users/<myUserName>/Documents/react-native-projects/<myAppName>/ios/build/Build/Products/Debug-iphonesimulator/<myAppName>.app
at SimulatorDriver._callee2$ (node_modules/detox/lib/devices/SimulatorDriver.js:28:19)
at tryCatch (node_modules/regenerator-runtime/runtime.js:64:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:299:22)
at Generator.prototype.(anonymous function) [as throw] (node_modules/regenerator-runtime/runtime.js:116:21)
at step (node_modules/detox/lib/devices/SimulatorDriver.js:1:809)
at node_modules/detox/lib/devices/SimulatorDriver.js:1:1008
child_process.js:524
throw err;
^
Error: Command failed: node_modules/.bin/mocha e2e --opts e2e/mocha.opts
at checkExecSyncError (child_process.js:481:13)
at Object.execSync (child_process.js:521:13)
at Object.<anonymous> (/Users/<myUserName>/Documents/react-native-projects/<myAppName>/node_modules/detox/local-cli/detox-test.js:46:4)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
I have an e2e folder in my project directory with three files: init.js, mocha.opts, and firstTest.spec.js.
firstTest.spec.js looks like this:
/* eslint-env node, mocha */
/* global element, expect, device, by */
describe('FiestTest', () => {
beforeEach(async () => {
await device.reloadReactNative()
})
it('Shoudl find the phoneInput field and the init value as "09"', async () => {
await expect(element(by.id('LoginPage-phoneInput'))).toBeVisible()
await element(by.id('LoginPage-phoneInput')).typeText('09991234567')
await expect(element(by.id('LoginPage-loginGuideTxt'))).toBeVisible()
await element(by.id('LoginPage-loginBtn')).tap()
})
it('Dummy1"', async () => {
await device.reloadReactNative()
})
it('Dummy2', async () => {
await device.reloadReactNative()
})
it('Dummy3', async () => {
await device.reloadReactNative()
})
})
init.js looks like this:
/* eslint-env node, mocha */
require('babel-polyfill')
const detox = require('detox')
const config = require('../package.json').detox
before(async () => {
await detox.init(config)
})
after(async () => {
await detox.cleanup()
})
And mocha.opts looks like this:
--recursive --timeout 120000 --bail
Your help is highly appreciated!
I ran the following command and it solved the build issue:
watchman watch-del-all; npm start -- --reset-cache
This solved the issue for me:
detox clean-framework-cache && detox build-framework-cache
I have faced this issue while implementing detox in my react native project.
I have fixed it just by using latest fixing the project.pbxproj file
basically fixing the license configuration.

Typescript+Gulp+Protractor => Cannot find module config.js

I am trying to run the protractor using gulp. I am able to run first two task but when I try to run the third task its not able to find the config.js file which is stored in below path (Windows system)
F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\config\config.js
gulpfile.js
import * as gulp from 'gulp';
import * as protractor from 'gulp-protractor';
gulp.task('webdriver-update', protractor.webdriver_update);
gulp.task('webdriver-standalone', protractor.webdriver_standalone);
gulp.task('run-prot', function () {
console.log('About to run the specs...........')
gulp.src(['ConvertedJSFiles/specs/*.js']).pipe(protractor.protractor({
configFile: 'ConvertedJSFiles/config/config.js'
})).on('error',function(e){
throw e;
});
});
console.log(protractor.getProtractorDir() + ' is the protractor directory ***');
Console Error
F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build>gulp run-prot
F:\Selenium2\Protractor\TypeScriptProject\node_modules\.bin is the protractor directory ***
[18:16:17] Using gulpfile F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\gulpfile.js
[18:16:18] Starting 'run-prot'...
About to run the specs...........
[18:16:18] Finished 'run-prot' after 106 ms
[18:16:20] E/configParser - Error code: 105
[18:16:20] E/configParser - Error message: failed loading configuration file ConvertedJSFiles/config/config.js
[18:16:20] E/configParser - Error: Cannot find module 'F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\Convert
edJSFiles\config\config.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at ConfigParser.addFileConfig (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\configParser.js:125:
26)
at Object.initFn [as init] (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\launcher.js:93:22)
at Object.<anonymous> (F:\Selenium2\Protractor\TypeScriptProject\node_modules\protractor\built\cli.js:112:10)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
F:\Selenium2\Protractor\TypeScriptProject\ConvertedJSFiles\build\gulpfile.js:11
throw e;
^
Error: protractor exited with code 105
Issue was with wrong directory reference. I debugged it with "path" package. below is the updated file.
import * as gulp from 'gulp';
import * as protractor from 'gulp-protractor';
import * as path from 'path';
gulp.task('webdriver-update', protractor.webdriver_update);
gulp.task('webdriver-standalone', protractor.webdriver_standalone);
gulp.task('run-prot', function () {
console.log('About to run the specs...........')
let srcfiles=path.resolve('../specs/*.js');
console.log(srcfiles);
gulp.src([srcfiles]).pipe(protractor.protractor({
configFile: '../config/config.js'
})).on('error',function(e){
throw e;
});
});
console.log(protractor.getProtractorDir() + ' is the protractor directory ***');

Importing AMD module in to Mocha test

I am using Mocha to test code exported as AMD module. Running mocha test gives me following error.
ReferenceError: define is not defined
at Object.<anonymous> (/home/malintha/projects/...../xxx.js:1:63)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
The source which is tested as floows
define(['lodash', 'log', './yyy'], function(_, log, YYY) {
var xxxy = function() {
};
..............
});
And the mocha test
var expect = require("chai").expect;
var sourceGenVisitor = require("../../xxx")
describe("", function() {
describe("", function() {
it("Checks generated source", function() {
...................
});
});
});
How can I fix this issue ?
You can use amd-loader. I used it for years in a project of mine that was structured as a collection of AMD modules. Install with:
`npm install amd-loader`
It then needs to be loaded before any AMD module. In general:
require("amd-loader");
For Mocha you can use the argument --require amd-loader. You can put it in your test/mocha.opts file if you don't want to have to remember typing it over and over.
If you run mocha test with the typescript. Maybe you do this:
Install amd-loader:
npm install amd-loader --save
Run mocha test:
mocha src/**/*test.ts --require ts-node/register -r amd-loader

node.js cannot find 'neo4j' module (Thingdom)

After many tries, I am unnable to connect node.js to Neo4j installed in my computer. I am able to access both separately, and both work fine. I have install in my Node.js directory the Thingdom ('neo4j') module in the directory, but when require('neo4j') prints an error.
Image of my Node.js folder with Neo4j installed in modules
var neo4j = require("neo4j");
var db = new neo4j.GraphDatabase("http://localhost:7474");
var node = db.createNode({hello: 'world'}); // instantaneous, but...
node.save(function (err, node) { // ...this is what actually persists.
if (err) {
console.error('Error saving new node to database:', err);
} else {
console.log('Node saved to database with id:', node.id);
}
});
And when using in the cmd: "node index.js" it throws me this error:
C:\Users\RRamos\Documents\Projects\test-neo4j>node index.js
module.js:341
throw err;
^
Error: Cannot find module 'neo4j'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\RRamos\Documents\Projects\test-neo4j\index.js:1:75)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
I got the same problem. As there's no solution in this post, I just add mine.
After running $ npm init and $ npm install --save neo4j-driver, I copy and paste the neo4j example code in index.js:
var neo4j = require("neo4j");
var db = new neo4j.GraphDatabase('http://neo4j:<password>#localhost:7474');
And then I got the same error when running $ node index.js.
In my package.json, I found:
"dependencies": {
"neo4j-driver": "^1.1.0-M02"
}
It's neo4j-driver not neo4j. So replace it in index.js:
var neo4j = require("neo4j-driver");
var db = new neo4j.GraphDatabase('http://neo4j:<password>#localhost:7474');
Now you will get rid of the Cannot find module 'neo4j' error!
In addition, if you use the 1.1.0 version of neo4j-driver(for Neo4j 3.0.0+), you may get this error:
var db = new neo4j.GraphDatabase('http://neo4j:<password>#localhost:7474');
^
TypeError: neo4j.GraphDatabase is not a constructor
at Object.<anonymous> (D:\Codes\neo4j_test\server.js:2: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)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3
It seems neo4j.GraphDatabase is only available in older version of neo4j-driver.
Here's the up-to-date tutorial of neo4j-driver.
Use the following code instead:
var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "<password>"));
// Create a session to run Cypher statements in.
// Note: Always make sure to close sessions when you are done using them!
var session = driver.session();
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
session
.run("MERGE (alice:Person {name : {nameParam} }) RETURN alice.name", { nameParam:'Alice' })
.subscribe({
onNext: function(record) {
console.log(record._fields);
},
onCompleted: function() {
// Completed!
session.close();
},
onError: function(error) {
console.log(error);
}
});

Categories

Resources