I'm using remark-math to render maths equations from Markdown. This has previously been working without a hitch, however after I refactored some seemingly unrelated code, I now get the following exception:
Uncaught ReferenceError: INLINE_MATH_DOUBLE is not defined
at Of.inlineTokenizer (inline.js:12)
at Of.tokenize [as tokenizeInline] (tokenizer.js:111)
at Of.atxHeading (heading-atx.js:148)
at Of.tokenize [as tokenizeBlock] (tokenizer.js:111)
at Of.parse (parse.js:41)
at Function.parse (index.js:275)
at pipelineParse (index.js:22)
at wrapped (index.js:93)
at next (index.js:56)
at Object.run (index.js:30)
The relevant code from ./node_modules/remark-math/inline.js looks like the following:
const ESCAPED_INLINE_MATH = /^\\\$/
const INLINE_MATH = /^\$((?:\\\$|[^$])+)\$/
const INLINE_MATH_DOUBLE = /^\$\$((?:\\\$|[^$])+)\$\$/ // << defined here?
module.exports = function inlinePlugin (opts) {
function inlineTokenizer (eat, value, silent) {
let isDouble = true
let match = INLINE_MATH_DOUBLE.exec(value) // << line 12, error here
// ...remaining code
The constant appears to be defined in scope!
I'm building using webpack and the chentsulin/electron-react-boilerplate template. Any hints as to why this kind of exception would suddenly be happening? (I've tried a complete reinstall of node_modules.)
maybe some issues happen from webpack building.
if the error still happen, and you want to avoid it, you can use this
GLOBAL.INLINE_MATH_DOUBLE = /^\$\$((?:\\\$|[^$])+)\$\$/
I reinstalled the dependencies with yarn instead of npm and the issue went away.
Related
I want to emit events from my Nodejs module but it's not working as expected as we are getting an error:
Uncaught TypeError: Test.on(...) is not a function.
Here is the module test.js
var util = require("util");
var EventEmitter = require("events").EventEmitter;
function Test() {
EventEmitter.call(this);
}
Test.prototype.test = function (input) {
this.emit("testevent", input);
};
util.inherits(Test, EventEmitter);
module.exports = Test;
And in the index.js we have the following:
const Test = new (require('./test.js'));
Test.on('testevent', function (test) {
console.log('emitted', test);
});
// Test.test('input');
I understand with just that code in index.js the event should never get emitted since Test.test('input'); is not called.
However, with that line disabled, I am confused about why I am getting Uncaught TypeError: Test.on(...) is not a function.
The error goes away once Test.test('input'); is uncommented and the event appears to emit as I can see the logged line. But why? Why is it throwing that error if the line is disabled? What are we doing wrong?
Using const Test = new (require('test.js')); you are require test.js module from node_modules and there is one because you don't have MODULE_NOT_FOUND error, but is this a file you really want to require, or maybe this should be local file with realative path const Test = new (require('./test.js'));
After uncommenting this line Test.test('input'); this is unlikely to log anything because this code emits test event and your code is listening for testevent only.
In general this code works well, here is a example https://repl.it/repls/DiscreteUnwrittenNet
I created a react-app which I deployed online with npm run build, now everything locally works fine but when I try to load a page on my app it gives a error in Container.js ( no idea what this file is and what it does )
i've tried to reinstall all the node_modules without any result so I cloned my repo fresh but still without any result
Container.js:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = require('react-redux');
var _Container = require('../components/Container');
var _Container2 = _interopRequireDefault(_Container);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* src/containers/Container.jsx
*/
var mapStateToProps = function mapStateToProps(store, ownProps) {
return {
items: store[ownProps.reduxStoreName].content[ownProps.reduxUid].filter(function (item) {
return item.parentId === ownProps.itemId;
})
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps)(_Container2.default);
Error in console: Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined
well, like #Pointy mentioned in his comment, it basically means that store[ownProps.reduxStoreName].content[ownProps.reduxUid] is undefined.
It is not the file which is causing the error, its the specific line. When the code reaches this line and tries to execute it- that store[ownProps.reduxStoreName].content[ownProps.reduxUid] parameter is undefined so it crushes.
We cannot tell you where the error is, we'd need the code of your whole app to follow the execution flow.
You have to follow it yourself, and understand why there is not an array in that variable when the code gets there.
As a general idea, try figure out the following:
when and where that variable is initialized?
when and where do you call mapStateToProps?
are you absolutely sure that the code which answers question 1 is executed before the code which answers to question 2? (maybe there is an asynchronous execution problem you didn't think about which causes your code to execute at the wrong order)
if it does- maybe the way you initialize those variables at the beggining is not correct? maybe you use a 3rd party library / function to initialize them, but not actually getting the result you expecting? or maybe you're using it wrong, or parsing the result wrong?
I am trying to test my code using expect in nodejs. I required expect in code and I wanted to use a feature of expect called toBeA(). But unfortunately I
am receiving error and unable to solve it. So,I am posting it here.
const utils = require('./utils');
const expect = require('expect');
it('should add two numbers', () => {
var result = utils.add(33,17);
expect(result).toBe(50).toBeA('number');
});
This is my utils.js file
module.exports.add = (a,b) => {
return a+b;
};
When I run the code I receive this error
TypeError: Cannot read property 'toBeA' of undefined
You cannot chain tests. toBe doesn't return anything, hence the error. You want
expect(result).toBe(50);
expect(result).toBeA('number');
(although the first one implies the other so you might as well omit it)
This works fine instead of toBeA()
expect(typeof result).toBe('number');
The expect assertion library has changed ownership. It was handed over to the Jest team, who in their infinite wisdom, created a new API.
You can still install expect as before, "npm install expect --save-dev", which is currently at version 21.2.1. Most methods names will remain unchanged except for a few, including 'toExist(), toBeA()'.
when use npm i expect --save-dev command for install expect, automatically install last version of expect. in last version chain do not work.
for solve this problem you should use below command:
npm i expect#1.20.2
in this version you can use chain expect like toNotBe.
I'm trying to use your relaxed-json in my Electron app. Here is a simple code, GetDeviceList() is triggered on a button-push action:
const driver = require('meteor_driver').MeteorConnection.MeteorConnection;
const relaxed = require('relaxed-json');
const connection = new driver();
function GetDeviceList() {
console.log(connection.port);
console.log("Launching");
console.log(relaxed);
relaxed.transform('[{id:0,},{id:1,},{id:2,},]');
}
The console.log show me an empty object. And I got an error message Uncaught TypeError: relaxed.transform is not a function.
Otherwise, the package works properly when it's not used with electron.
Note that I don't encounter any require-related issue, so the modules must be valid isn't ?
I am using requireJS for the first time. I got it working fine then came to optimize the files to minify and concatenate and now I get the error "Uncaught TypeError: undefined is not a function" the error is on line 8175 of front-built.js. I have left the file unminifed for this question to make it easier to identify the problem.
My main JS file before optimization looks like this (works fine):
http://thebeer.co/js/front.js
And after optimization (throws the error on line 8175):
http://thebeer.co/js/front-built.js
Hope someone is more familier with requireJS than me and can fix this issue. Is may be the way I'm including my JS file before optimization. I'm really not sure.
I see the problem there:
define('globals',["jquery"],(function($){
var siteWrap = $('#siteWrap'),
membersTab = $('#membersTab'),
mID = siteWrap.attr('mID');
if(window.location.host == "dev.thebeer.co"){
var staticURL = "http://static.thebeer.co";
}else{
var staticURL = "https://static.meshmesh.us";
}
// ... SNIP SNIP ....
})());
You're not passing jQuery to the anonymous function, therefore $ is undefined inside the function. That last line should be like this:
})(jQuery));