Dustjs custom filters stopped working - node.js

For some reason my dustjs custom filters have just stopped working on the production server, even though they work fine on my local machine. Anyone have any thoughts as to why this might be happening? I am using dustjs-linkedin v. 2.3.5.
What my filters look like (located in my main server.js file):
dust.filters.uppercase = function (value) {
return String(value).toUpperCase();
};
dust.filters.ucwords = function (value) {
return String(value).replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function($1) {
return $1.toUpperCase();
});
};
dust.filters.money = function (value) {
return parseFloat(value).toFixed(2);
};
UPDATE: I really need this fixed, and am at a loss as to why this would work locally, but not on my server (this used to work just fine). Unfortunately, I didn't notice when it stopped working and have made MANY updates. Any ideas would be GREATLY appreciated.
Here are the app dependencies from my package.json:
"dependencies": {
"express": "3.4.8",
"socket.io": "0.9.16",
"dustjs-linkedin": "2.3.x",
"dustjs-helpers": "1.2.0",
"consolidate": "0.10.0",
"mongoose": "3.8.x",
"node-uuid": "1.4.1",
"express-form": "0.10.1",
"bcrypt-nodejs": "0.0.3",
"subdomain": "0.1.0",
"gm": "1.14.x",
"connect-mongo": "0.4.1",
"nodemailer": "0.6.5"
}
ANOTHER UPDATE: I have added a console.log('money'); to the money filter and it logs every time it is run locally just fine, but never logs anything to the console on the production end. This leads me to believe that the custom filters are not being added on the production server for some reason.
YET ANOTHER UPDATE: I literally added the filters to the dust source code, and they still wont run on the production server, but work fine locally. Could using NODE_ENV somehow be causing something to mess up in dust?

Inspect the node_modules directory tree. My guess is you will find two instances of dustjs-linkedin. Your filters will be in one but you are using the other one. Something else is dragging in the other copy based on a different version.

I think it happened because you have updated some packages to more recent versions.
I have similiar thing with nodemailer package upgrade from 0.7.1 to 1.0.2 versions
Can you prodive the dependecies hash of package.json file?

Related

React native : Failed to construct transformer: Error: Cannot create a string longer than 0x1fffffe8 characters

package.json
{
"name": "project",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/async-storage": "^1.12.0",
"#react-native-community/clipboard": "^1.2.3",
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/drawer": "^5.9.0",
"#react-navigation/native": "^5.7.3",
"#react-navigation/stack": "^5.9.0",
"#twotalltotems/react-native-otp-input": "^1.3.11",
"jetifier": "^1.6.6",
"react": "16.13.1",
"react-native": "^0.63.2",
"react-native-barcode-builder": "^2.0.0",
"react-native-biometrics": "^2.1.4",
"react-native-chart-kit": "^6.6.1",
"react-native-gesture-handler": "^1.7.0",
"react-native-image-picker": "^2.3.3",
"react-native-localization": "^2.1.6",
"react-native-paper": "^4.0.1",
"react-native-reanimated": "^1.13.0",
"react-native-safe-area-context": "^3.1.6",
"react-native-screens": "^2.10.1",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^12.1.0",
"react-native-swipe-list-view": "^3.2.3",
"react-native-vector-icons": "^7.0.0"
},
"devDependencies": {
"#babel/core": "7.11.4",
"#babel/runtime": "7.11.2",
"#react-native-community/eslint-config": "1.1.0",
"babel-jest": "25.5.1",
"eslint": "6.8.0",
"jest": "25.5.4",
"metro-react-native-babel-preset": "0.59.0",
"miragejs": "^0.1.40",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}
i did't fonund any answers related this except this : https://github.com/facebook/react-native/issues/28189
but it won't work for me...
myapp successfully install on android emulator but stuck at splash screen ...
the app works fine in my office computer but it did't work on my own computer
my node version : v14.10.0
so please help me.
I've tried to log the file that causing the error, but console.log wasn't working.
I come up with a quick hack to throw filePath then I've saw that a zip file, that I keeped as a backup, was the issue.
For some way react doesn't liked it so I have to move it outside of the project folder
For others having the same problem, and looking for a way to debug:
Edit /node_modules/jest-haste-map/build/worker.js
Wrap readFileSync in a try...catch, like this:
const getContent = () => {
if (content === undefined) {
try {
content = fs().readFileSync(filePath, 'utf8');
} catch (err) {
throw new Error(`error readFileSync ${filePath} : ${err.message}`);
}
}
return content;
};
(re)start metro bundler:
/node_modules/react-native/scripts/launchPackager.command; exit
My output:
To reload the app press "r"
To open developer menu press "d"
Failed to construct transformer: Error: error readFileSync <my project path>/some/big/file/that/caused/error : Cannot create a string longer than 0x1fffffe8 characters
at getContent (<my project path>/node_modules/jest-haste-map/build/worker.js:133:15)
at Object.worker (<my project path>/node_modules/jest-haste-map/build/worker.js:162:23)
at execFunction (<my project path>/node_modules/jest-worker/build/workers/processChild.js:145:17)
at execHelper (<my project path>/node_modules/jest-worker/build/workers/processChild.js:124:5)
at execMethod (<my project path>/node_modules/jest-worker/build/workers/processChild.js:128:5)
at process.messageListener (<my project path>/node_modules/jest-worker/build/workers/processChild.js:46:7)
at process.emi
Hope this helps others having the same problem!
I was running into the same problem.
warning: the transform cache was reset.
Welcome to React Native!
Learn once, write anywhere
Failed to construct transformer: Error: Cannot create a string longer than 0x1fffffe8 characters
at Object.slice (buffer.js:608:37)
at Buffer.toString (buffer.js:805:14)
at Object.readFileSync (fs.js:421:41)
at getContent (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:149:41)
at Object.<anonymous> (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:
199:9)
at Generator.next (<anonymous>)
at asyncGeneratorStep (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:
78:24)
at _next (J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:98:9)
at J:\expoProjects\rn-cnn\node_modules\metro\node_modules\jest-haste-map\build\worker.js:103:7
at new Promise (<anonymous>) {
type: 'Error',
code: 'ERR_STRING_TOO_LONG'
I solved the error by changing the node version to v14+ and then reverting back to the old version of node v10.15.3.
I've run into the exact same error. Turns out it was an auto-generated big file from gradle (> 700MB) inside "android.gradle\6.0.1\executionHistory"
To figure out what file caused an error I used #dirk approach.
I don't sure why but my App_name.app.dSYM.zip became too large (536MB) so the node was unable to read it because of the 512MB limitation. It might be some different file in your case.
Here is a patch-package to get more information about the file which caused this error
diff --git a/node_modules/jest-haste-map/build/worker.js b/node_modules/jest-haste-map/build/worker.js
index 1996d4a..1f17f11 100644
--- a/node_modules/jest-haste-map/build/worker.js
+++ b/node_modules/jest-haste-map/build/worker.js
## -146,7 +146,11 ## function _worker() {
const getContent = () => {
if (content === undefined) {
- content = _gracefulFs().default.readFileSync(filePath, 'utf8');
+ try {
+ content = _gracefulFs().default.readFileSync(filePath, 'utf8');
+ } catch (err) {
+ throw new Error(`error readFileSync ${filePath} : ${err.message}`);
+ }
}
return content;
Make sure you don't have any large files in your root project including (mp4, images, .zip, etc)?
In my own case I noticed I was using an mp4 video file for my react native application which was too large in size. I had to delete it and that was the fix for me
It took me the whole day but I solved it. I still can't understand why I'm getting this error when I want to launch the app on iOS but:
removing the build directory in android/app fixed it.
Check if there any unrelated file or zip in your project structure/folder
if yes then delete file and error will be resolved
In my case there was a zip file of whole project in the project directory which cause the issue when I remove it from the project directory and run
npm start --reset cache
it worked for me.
I had similar issue. After some debugging I found that it crashes because of asset file, which was generated by android build previously.
I don't know why it is trying to import this file (I experience this issue on ios), but when I removed folder ./android/app/build it started working.
Even if issue is not related to this dir in your case, you need to find which asset caused this issue.
Moving any large asset files [pictures,videos,etc...] up out of the project directory.
https://github.com/facebook/react-native/issues/28189#issuecomment-592918995
I got this error when i run build.
But This fix worked for me.
I deleted a zip file at the root of my app (I compressed the whole project to zip at end of the previous day for backup)
And i stopped the server with ctr + c command
Then restarted the server with npx react-native start
All now works fine after restarting the server and without having to run build again.
Just delete any zipped file in your project root directory. In my case I had packaged the app and sent it to someone and forgot to remove the zipped file thereafter.
This answer helped me a lot https://stackoverflow.com/a/41963217/2915928
For my case my app had a lot of audio files being included in android app bundle, this was then creating a large zip file in android/build/intermediates. So rather than deleting the build folder this tell the packager to ignore the file causing the issue.
Here is an example of my fix replace asset_pack_bundle with whatever file or directory you are having an issue with.
const exclusionList = require('metro-config/src/defaults/exclusionList');
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
blacklistRE: exclusionList([/asset_pack_bundle\/.*/]),
},
};
I have followed the below steps and it worked for me:
1. cleared cache and unnecessary space from my mac.
2. cleared npm cache and watchman.
3. cleared gradle.
4. restarted the metro server.

Router location doesn't finish updating after history.push()

I am using react-router-dom to navigate to different pages in my app. I have been testing things all day long and with different scenarios end up with the following:
I target an invalid path, which should redirect me to the home path
I push/replace the history
the browser URL updates fine
but the location doesn't finish updating, I end up stuck in a half baked value such as this (rendering stops half way):
location: {"action":"REPLACE","location":{"pathname":"/home","search":"","hash":"","state":null,"key":"ui1fiedd"}}
Whereas a correct value would be:
location={"pathname":"/home","search":"","hash":"","state":null,"key":"ui1fiedd"}
This happens when I use different approaches:
call history.push(newPath)
render <Redirect to="/home" />
render <Redirect to={{ pathname: "/home" }} />
with or without the push option
getting location from withRouter, from useLocation(), or from a Route render call
I don't have a good clean test case right now, all of this is in a pretty complex and big app. But does this ring any bell? I am surely doing something wrong, but have been looking at it all day and cannot see it.
My dependencies are:
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
Thanks!
Edit 8/9/2020
This looks to be a package version issue... I had recently done a few updates. Thought this might the issue, so reverted my package.json, ran npm i and thought I was ok...
I just wiped my modules, package-lock.json and re-ran npm i, now all is fine.
So the following transition screwed things up somewhere:
"#material-ui/core": "^4.9.8" >> "^4.11.0"
"history": "^4.10.1" >> "^5.0.0"
"react-helmet": "^5.2.1" >> "^6.1.0"
"react-router-dom": "^5.1.2" >> "^5.2.0"
"react-scripts": "^3.4.1" >> "3.4.1"
I should have looked at this ^5.0.0 version more closely :-)
Mind you, I also had really strange behaviour at the same time with this transition:
"react-tabulator": "^0.10.3" >> "^0.13.2"
Some pages containing tabulator tables could not load at all any more.
Issues were due to some incompatibility between some package/scripts versions, as described in the question's body.

Proper use of karma-commonjs with Jasmine 2

I've spent a fair amount of time trying to debug this, and figured I would ask. I even created a GitHub repository but won't rely on it, so here goes. I'm trying to take advantage of CommonJS syntax within the Karma test runner using PhantomJS. For my module I created the simplest thing I could think of:
exports.returnYes = function() {
return "Yes";
};
The Jasmine test is:
var returnYes = require("../js/returnYes").returnYes;
describe("returnYes", function() {
it("should return Yes", function() {
expect(returnYes()).toBe("Yes");
});
});
And, if I do a jasmine init I can run it from the command line thanks to jasmine-npm by simply typing jasmine with output:
$ jasmine
Started
.
1 spec, 0 failures
Finished in 0.003 seconds
Now to try and get it to work inside karma:
I create my karma.conf.js with frameworks: jasmine,commonjs. And, I add commonjs as preprocessor.
I try to do a karma run and I find that it can't find global which is part of getJasmineRequireObj in jasmine.js where it declares jasmineGlobal = global;
The command line output is a little hard to read, but here it is:
$ karma run
[2015-06-27 17:41:35.266] [DEBUG] config - Loading config /Users/zen/Projects/karma-commonjs-test/karma.conf.js
##teamcity[enteredTheMatrix]
##teamcity[testSuiteStarted nodeId='1' parentNodeId='0' name='karma.conf.js' nodeType='config' locationHint='config:///Users/zen/Projects/karma-commonjs-test/karma.conf.js']
##teamcity[testSuiteStarted nodeId='2' parentNodeId='1' name='PhantomJS 1.9.8 (Mac OS X 0.0.0)' nodeType='browser']
##teamcity[testStarted nodeId='3' parentNodeId='2' name='Error' nodeType='browserError']
##teamcity[testFailed nodeId='3' error='yes' message='ReferenceError: Can|'t find variable: global|nat http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?68f13ab3f93af5a219b9fe8409f8763b31998bba:27']
##teamcity[testSuiteFinished nodeId='2']
##teamcity[testSuiteFinished nodeId='1']
For good measure here are the devDependencies in my packages.json:
"devDependencies": {
"jasmine-core": "^2.3.4",
"karma": "^0.12.37",
"karma-commonjs": "0.0.13",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17"
}
I'm not sure why I can't find global. Any help would be greatly appreciated!!! :)
It seems like my whole problem came down to the line in karma.conf.js (not shown in my original question:
preprocessors: {
'**/*.js': ['commonjs']
},
For some reason, jasmine.js is not happy being pre-processed by commonjs, and "**/*.js" says to go through all subdirectories (which is probably overkill), including node_modules which has jasmine-core/jasmine.js
So I can either make my pre-processor more specific (best practice):
preprocessors: {
'spec/*.js': ['commonjs'],
'js/*.js': ['commonjs']
},
but as a test to see if any other files would give me a problem, I tried:
preprocessors: {
'**/!(jasmine).js': ['commonjs'],
},
And, everything worked as well. Bottom line. Do not process jasmine.js through commonjs preprocessor!

How to integrate foundation for apps into an existing Express framework

OK, I'm fairly new to all this front end programming and I hope my question is not silly.
I have an existing app made with an express.js framework with a custom gulp config and ejs. Now, I want to integrate the all new shiny Foundation for Apps into it.
On the Zurb website, the manual install is only a one-liner through bower or npm (http://foundation.zurb.com/apps/docs/index.html#!/installation)
bower install foundation-apps --save
npm install foundation-apps --save
So that's what I did, but the Foundation formatting is not happening at all.
I tried to include the CDN reference lines (css and js) too, but the same is happening.
When I proceed to create an app with the "normal" installation, everything is working great. But I want to use the Express framework and this is not the case here!
I am missing something but I don't see what.
package.json
{
"name": "2004app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"apache-server-configs": "^2.7.1",
"body-parser": "~1.12.0",
"browser-sync": "^1.3.0",
"cookie-parser": "~1.3.4",
"debug": "~2.1.1",
"del": "^1.1.0",
"ejs": "~2.3.1",
"express": "~4.12.2",
"foundation-apps": "^1.1.0",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^2.0.0",
"gulp-cache": "0.2.2",
"gulp-changed": "^1.0.0",
"gulp-concat": "2.5.2",
"gulp-csso": "^1.0.0",
"gulp-flatten": "0.0.4",
"gulp-if": "^1.2.1",
"gulp-imagemin": "^2.0.0",
"gulp-jshint": "^1.6.3",
"gulp-load-plugins": "^0.8.0",
"gulp-minify-html": "0.1.5",
"gulp-nodemon": "^2.0.2",
"gulp-rename": "1.2.2",
"gulp-replace": "^0.5.0",
"gulp-sass": "^1.2.0",
"gulp-size": "^1.0.0",
"gulp-sourcemaps": "^1.3.0",
"gulp-uglify": "^1.0.1",
"gulp-uncss": "^1.0.0",
"gulp-useref": "^1.0.1",
"jshint-stylish": "^1.0.0",
"morgan": "~1.5.1",
"opn": "^1.0.0",
"psi": "^1.0.4",
"require-dir": "^0.1.0",
"run-sequence": "^1.0.1",
"serve-favicon": "~2.2.0"
}
}
For example, the following code is not rendering like it should. It only shows a line with 3 times "Content goes here", instead of this : http://foundation.zurb.com/apps/docs/#!/accordion
<zf-accordion>
<zf-accordion-item title="Input your title here">
Content goes here
</zf-accordion-item>
<zf-accordion-item title="Input your title here">
Content goes here
</zf-accordion-item>
<zf-accordion-item title="Input your title here">
Content goes here
</zf-accordion-item>
</zf-accordion>
Is what I am trying to do possible ?
How can I use the CDN references ? (I successfully put CDN references for bootstrap in another app)
Thanks!
It is possible!
Though it has quite a few moving pieces that you should understand.
I recently did the same thing, but depending on the size of your app's frontend it may take some time to understand everything that is going on. It's not as simple as just including a library.
You mention express app, is it an Angular app? First thing if your not familiar with Angular I would read about it and specifically 'Modules' as in the end that is all Foundation Apps is.
https://docs.angularjs.org/guide/module
You will need to create your angular module and have Foundation as dependency.
Also it is good to realize that the way that foundation for apps is packaged its meant to be compiled in its own weird sort of way. So basically whenever you make changes your re-compiling your front end html/logic/css.
Make sure your express app is serving up the Single Page Application which is Foundation Apps. Be sure to watch your web development console to see if your getting any strange Angular errors. If you are you can typically click on them and get help from the angular site.
Also the Foundation Apps gulp task is unique in it has its own little plugin to create the routing based off the templates. See the following link:
http://foundation.zurb.com/apps/docs/#!/angular
If your just getting into Front End Frameworks I would suggest going through a few basic Angular tutorials before tackling a angular app such as Foundation Apps.
Once familiar with Angular look at exactly what the Gulp build is doing (gulpfile.js). It takes care of the following:
Copies static resources
Its running SASS and compiling styling
Copies Foundation for Apps Javascript
Copies the templates and builds the routes (the route building is a little hidden
Once you understand what the Gulpfile.js is doing you should start to piece together how the front end is built.
I reworked it using Grunt, but ended up switching back to gulp because of their template job (ngHtml2js)
Don't giveup, be persistent and it will slowly make sense!
I'm working on the same task you mentioned up there, an existing MEAN application, that I developed with ejs front end template, and a front-end that I developed with the foundation-apps tools, the front-end has everything I need for my MEAN back-end, now for merging all of this together into a single node app.
UI is developed independently using foundation for app build tools such as gulp, considering my UI is developed with all the zurb foundation html parts are included to represent all the required functions served by my MEAN app. So after the build with foundation-apps the resulting build folder contains basic assets without any SASS or the need for foundation-apps to be in the package.json dependencies, since the foundation.js file is in the assets folder for the front-end, and sass is already built into app.css
I dont see how it's possible to have two single page web apps running on the same node server, in case I try separating the two different app configurations, angular dependency injection, routes, index files separated etc..
The challenge is wrapping up a single page web app with all dependencies, while maintaining how the foundation UI manages it's routing, as it is quite different from how express manages routing, it happens using different libraries.

Using two different versions of the same node dependency

Is there a way to include two versions of the same dependency in nodejs package.json?
For testing purposes, I need to use two versions of socket.io (one to expose a socket in the latest version and one to simulate a dependency server using an old release).
{
"dependencies": {
"socket.io": "~0.9.0",
"socket.io": "~1.2.0"
}
}
Maybe not the best solution, but you can first fork socket.io 0.9 on github:
https://github.com/Automattic/socket.io/tree/0.9
To create https://github.com/youaccount/socket.io/tree/0.9
Then use this:
"dependencies": {
"oldsocket.io": "git+ssh://git#github.youaccount/socket.io.git#0.9",
"socket.io": "~1.2.0"
}
Edit the package.json and rename the name attribute to oldsocket.io
And you can now require socket.io or oldsocket.io

Resources