Trouble getting Mocha, node.js and WebStorm to work with each other - node.js

I have been following the instructions to install Mocha with WebStorm found here: https://www.jetbrains.com/help/webstorm/2017.1/testing-javascript-with-mocha.html#d194239e92
I have set the configurations to run files that match the pattern: **/*.spec.js
node interpreter: /usr/bin/node
working directory:/home/web/app
mocha package:/home/web/app/node_modules/mocha
I am writing in TypeScript which is converted to ES6, the output of which is what I'm attempting to test. However I get this error which I don't understand and so don't really know where to begin looking to resolve.
I don't understand why it is looking for "ts-node", considering it's only supposed to look for "spec.js" files. and past that, I don't understand why the folder it is looking for in ts-node is missing. I have uninstalled then re-installed ts-node a couple times, neither of which yielded the sought after folder... I have no clue as to how to proceed or even what further information is needed to help resolve this issue.
Any help would be appreciated. I just want to test my application and this is proving to be a real headache.
Here is the error:
/usr/bin/node /home/web/app/node_modules/mocha/bin/_mocha --ui bdd
--reporter /opt/webstorm/ws/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js
**/*.spec.js TypeError: The specified path does not exist: /home/web/app/node_modules/ts-node/tests
at resolveSync (/home/web/app/node_modules/ts-node/node_modules/tsconfig/src/tsconfig.ts:72:9)
at Object.loadSync (/home/web/app/node_modules/ts-node/node_modules/tsconfig/src/tsconfig.ts:140:16)
at readConfig (/home/web/app/node_modules/ts-node/src/index.ts:418:18)
at Object.register (/home/web/app/node_modules/ts-node/src/index.ts:176:18)
at Suite. (/home/web/app/node_modules/ts-node/src/index.spec.ts:190:5)
at Object.create (/home/web/app/node_modules/mocha/lib/interfaces/common.js:114:19)
at context.describe.context.context (/home/web/app/node_modules/mocha/lib/interfaces/bdd.js:44:27)
at Suite. (/home/web/app/node_modules/ts-node/src/index.spec.ts:189:3)
at Object.create (/home/web/app/node_modules/mocha/lib/interfaces/common.js:114:19)
at context.describe.context.context (/home/web/app/node_modules/mocha/lib/interfaces/bdd.js:44:27)
at Object. (/home/web/app/node_modules/ts-node/src/index.spec.ts:13:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /home/web/app/node_modules/mocha/lib/mocha.js:230:27
at Array.forEach (native)
at Mocha.loadFiles (/home/web/app/node_modules/mocha/lib/mocha.js:227:14)
at Mocha.run (/home/web/app/node_modules/mocha/lib/mocha.js:495:10)
at Object. (/home/web/app/node_modules/mocha/bin/_mocha:460:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:505:3
Process finished with exit code 1

I figured it out, my path was from the root of my project, which contained node_modules, and so the node_modules directory was being tested, causing errors from tests inside the ts-node folder. the fix was to exclude node_modules directory from the specified path for test modules.

Related

Cannot find module 'm3u8stream/lib/parse-time'

is there anyway to fix this? I've been trying to resolve this myself but I give up
throw err;
^
Error: Cannot find module 'm3u8stream/lib/parse-time'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/rbd/pnpm-volume/71b5ddd8-2a78-46fc-aba4-68049f14880d/node_modules/.registry.npmjs.org/ytdl-core/1.0.0/node_modules/ytdl-core/lib/info-extras.js:5:21)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
This works for me, at the root of the project:
cp -r ./node_modules/m3u8stream/dist ./node_modules/m3u8stream/lib
I really don't understand why, I assume is some bug of versions, (mentioned in the previous comments) cause for some reason it needs the both folders dist and lib (with the same content apparently)
Solved by: Chills
Comment: did you install parse-time?
Answer: no I didn't, I did get it installed but also I've learned from a friend about ytdl-core update required dist instead of lib
Source: https://github.com/fent/node-ytdl-core/pull/520
Solution:
packages needed installing: m3u8stream and parse-time
code needed in main file:
const m3u8stream = require('m3u8stream');
const parseTime = require('m3u8stream/dist/parse-time');

Electron: TypeError: Cannot create property 'default' on symbol 'Symbol(nodejs.util.inspect.custom)'

I've developed an electron app with following tech stack:
NodeJS (10.15) with Babel to allow ES6 import/export syntax.
Sequelize on SQLite and GraphQL to handle an internal database.
ReactJS (bundled) for views.
I've configured everything to work with Electron and running "electron" command in project root folder works without errors.
Now i'm trying to distribute it using this tutorial: https://electronjs.org/docs/tutorial/application-distribution
So i've simply downloaded the 4.1.4 binaries for windows and moved the project folder under resources/app/
But running the electron.exe i've the following error:
App threw an error during load
TypeError: Cannot create property 'default' on symbol 'Symbol(nodejs.util.inspect.custom)'
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\nodejsCustomInspectSymbol.js:18:84)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\nodejsCustomInspectSymbol.js:20:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Module._compile (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Object.newLoader [as .js] (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\defineToJSON.js:8:57)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\defineToJSON.js:36:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Module._compile (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Object.newLoader [as .js] (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
i've also tried to run npx electron resources/app/ from binaries folder and i've got the same error.
So i think the issue is something about the paths.
i've also tried electron-packager and the error is the same because this tool does the same process of guide above.
What can i do to fix it?
UPDATE1: after some investigations i've found that babel causes the issues. I guess when you run a project from a parent folder. I'm trying to find a solution
i've solved using this kind of configuration for babel/register:
const rootPath=path.resolve(path.join(__dirname, "../../"));
require("#babel/register")({
root: rootPath,
extends: path.join(rootPath, '.babelrc'),
ignore: [/node_modules/],
only: [rootPath],
})

Function load error: Code in file index.js can't be loaded. firebase functions issue

I am trying to deploy new functions in my firebase project but it started showing an error. I have 5 functions in my index.js file and at any given point, 4 functions are getting deployed and one is throwing this error.
⚠ functions[whenUserIsAdded]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-functions'
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 Object.<anonymous> (/user_code/index.js:1:79)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
This happens every time to any one of the 5 functions and this happens in random. I deployed the same code about 2 hours ago and it went smooth. Now after adding some console.log statements, it is showing this error at random with a function.
Can anybody help me with this issue. Thanks in advance.
Also, I am on the blaze plan.
Ok. I think I found the issue. I was having firebase-functions V0.6.3. I believe that was depreciated. Hence it was not working I updated my package.json to the following and it worked. Because functions is still in Beta, I dont think we can do anything about this.
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",

Custom dependency require Electron

With the package.json, it's possible to do something like this
"dependencies": {
"WindowManager": "./lib/WindowManager"
},
But when trying to do this in Electron, it gives me this error:
App threw an error during load
Error: Cannot find module 'WindowManager'
at Module._resolveFilename (module.js:470:15)
at Function.Module._resolveFilename (.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (.../desktop/lib/init.js:15:35)
at Object.<anonymous> (.../desktop/lib/init.js:22:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
Is it because of Electron, or am I doing something wrong?
./lib/WindowManager is a folder with a package.json in it with a main pointing to the WindowManager.js, so that should work.
The case you try to do normally works, make sure that the dependency "WindowManager" has been properly copied by the build tools to either:
.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/app.asar/node_modules
or
.../desktop/node_modules/electron/dist/Electron.app/Contents/Resources/node_modules
If WindowManager does not exist in the disted node_modules there is something wrong with your build process, hard to be more precise than that.

Mongoose: Error cannot find module debug

I'm building a basic MEAN webapp and am new to the stack. I have the front end running, but as soon as I add the following lines to app.js:
var mongoose = require('mongoose');
require('./models/test');
mongoose.connect('mongodb://localhost:3000/design-data-test');
I get the following error in terminal:
Error: Cannot find module 'debug'
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/username/node_modules/mongoose/node_modules/mquery/lib/mquery.js:11:13)
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)
And all of my front end code stops running. Mongodb is running on the default port.
How would I go about resolving this error?
For future visitors: You are probably missing a dependency. Make sure you run this first:
npm install
... before you run your app with npm start or node <app>
I think this may happen if you have a child dependency on debug through another package (for example express or mongoose) but you did not provide the dependencies' package.json files with the deployed application which makes node.js unable to locate debug.

Resources