I am new to Node.js. I want to work with internationalization. I am trying using i18next. I have written this code:
i18n.init({
lng: 'en',
debug: true,
load: ['en', 'ar'],
fallbackLng: 'en',
backend: {
"loadPath": path.join(__dirname,"locale/en/translation.json")
},
getAsync:false
}, (err, t) => {
console.log("this is key value :"+(t("key")));
return t;
});
And in my en/translation.json file I have this contents:
{
key:"hello anil"
}
When I run the program I get this error: i18next::translator: missingKey en translation key key
What went wrong? Please help me out.
Check your debug log.
I found the loadPath is not what I thought, after fixing the path it works.
The reason is my js file is in build directory, so the path becomes build/locales/en.json not /locales/en.json.
the error message,
[Error: ENOENT, open '/opt/www/build/locales/en.json']
errno: 34,
code: 'ENOENT',
path: '/opt/www/build/locales/en.json' } ]
this is my fixed config,
backend: {
loadPath: 'locales/' + '{{lng}}.json',
},
Related
With the following webpack.mix.js file
const mix = require("laravel-mix");
// Laravel Mix plugins for additional capabilities
require("laravel-mix-purgecss");
require("laravel-mix-criticalcss");
// CSS Plugins
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const presetenv = require("postcss-preset-env");
mix.setPublicPath('../public_html/assets/')
.sass(pkg.paths.src.scss + "master.scss", "css/master.min.css")
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind.config.js') ],
})
.js(pkg.paths.src.js + "site.js", "js/site.min.js")
.sourceMaps()
.browserSync({
proxy: "domain.local",
notify: {
styles: {
top: 'auto',
bottom: '0'
}
},
files: [
"src/scss/*.scss",
"templates/*.twig",
"templates/**/*.twig",
"templates/*.js",
"templates/**/*.js"
]
});
// mix.disableSuccessNotifications();
if (mix.inProduction()) {
mix.webpackConfig({
plugins: [],
})
.criticalCss({
enabled: true,
paths: {
base: 'https://domain.local',
templates: './templates/_inline_css/',
suffix: '.min'
},
urls: [
{ url: '/', template: 'index' },
],
options: {
minify: true,
timeout: 1200000,
},
})
.version();
}
when I run npm run production I get:
98% after emitting HtmlCriticalWebpackPlugin(node:58149) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined.
What's confusing about this is that at one point this was working OK. My list of URLs is longer than what I've displayed above. And the first time I tried it, it successfully output CSS files but I was getting problems with timeouts so started doing a few at a time.
I was able to successfully run it two or three times before the above error appeared and now it won't compile anymore. I even went back and tried the same bundles I'd tried before but it wouldn't work the second time around.
I've also tried a similar set-up using Gulp but get the same error.
Has anyone else ever got this? How did you solve it?
I want to create a CLI for bootstrap my project. Everything works find but in order to copy my template files I use ncp where I give the template directory as a argument. So I tried,
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
import { promisify } from 'util';
const access = promisify(fs.access);
...
const templateDir = path.resolve(
new URL(import.meta.url).pathname,
'../../templates',
'project_name'
);
try {
await access(templateDir, fs.constants.R_OK);
} catch (err) {
console.error('%s Invalid template name', chalk.red.bold('ERROR'));
process.exit(1);
}
...
I got ERROR Invalid template name
Then I tried to figure out the problem,
//* after getting ERROR Invalid template name
//* checking file exist or not
fs.stat(templateDir, function (err, stat) {
if (err == null) {
console.log('File exists');
} else if (err.code === 'ENOENT') {
// file does not exist
console.log("file doesn't exit");
} else {
console.log('Some other error: ', err.code);
}
});
file doesn't exit
[Error: ENOENT: no such file or directory, access 'G:\G:\CLI%20project\create-project\templates\javascript'] {
errno: -4058,
code: 'ENOENT',
syscall: 'access',
path: 'G:\\G:\\CLI%20project\\create-project\\templates\\javascript'
}
ERROR Invalid template name
I expect the access should be G:\CLI%20project\create-project\templates\javascript but it's not giving the that. where was the wrong happened? by the way I use esm module loader.
Give your errors a good read.
[Error: ENOENT: no such file or directory, access 'G:\G:\CLI%20project\create-project\templates\javascript'] {
errno: -4058,
code: 'ENOENT',
syscall: 'access',
path: 'G:\\G:\\CLI%20project\\create-project\\templates\\javascript'
}
They're not trying to trick you. They're just telling you/
G:\\G:\\
Error messages are there for a reason .
I had the same issue and found the answer:
const templateDir = path.resolve(
new URL(import.meta.url).pathname, // This is where it gives the error
'../../templates',
options.template
);
Change new URL (import.meta.url).pathname to __filename. It worked for me.
I'm trying to make a download link on my server for a zip file and I'm currently getting this error: (Note, still just testing it on local machine)
{ [Error: ENOENT: no such file or directory, stat 'C:\Users\Jordan\Desktop\Websites\HappyCamel\Users\Jordan\Desktop\Websites\HappyCamel']
errno: -4058,
code: 'ENOENT',
syscall: 'stat',
path: 'C:\\Users\\Jordan\\Desktop\\Websites\\HappyCamel\\Users\\Jordan\\Desktop\\Websites\\HappyCamel',
expose: false,
statusCode: 404,
status: 404 }
The relevant code is this:
router.get('/file/:name', function(req, res, next) {
console.log('test123'); //successfully prints to console
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
console.log('test456'); //successfully prints to console
if(err) {
console.log(err) //I'm assuming this is source of logged error
} else {
console.log("no error"); //doesn't print
}
});
})
edit:
Fixed it with changing this line:
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
to
res.download('./test123.zip', 'test123.zip', function(err) {
but now I get
angular.min.js:114 ReferenceError: success is not defined
error on my browser, but no errors in my node console (my "no error" line is printing)
you are using relative path. when you do this:
res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
it will look for Users/Jordan/Desktop/Websites/HappyCamel/ inside your current file's directory. looks like what you need is full path, or better a correct relative path- from the error it looks like the file is located with your code, so this should do:
res.download('./', 'test123.zip', function(err) {
I am using PayPal-node-SDK module in my Node JS application to create a payout.
My code is
var paypal = require('paypal-rest-sdk');
paypalRequest = { sender_batch_id: 'h4mq5b3xr',
email_subject: 'You have a payment' },
items:
[ { recipient_type: 'EMAIL',
amount: { value: 100, currency: 'USD' },
receiver: //sandbox text account,
note: 'Thank you.' } ]
}
return paypal.payout.create(paypalRequest, true, function (paypalErr, paypalResponse) {
console.log('paypalErr',paypalErr);
console.log('paypalResponse',paypalResponse);
}
But when i call the function i am getting the error
paypalErr { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
paypalResponse undefined
can anyone suggest what is the error and how can i rectify it?
Please help.
I found the solution. When run the corresponding function , i was using the local url (eg: 192.122.2.2) . That why it was showing the error. But when i tried to run the same on live (eg www.example.net) the function is working properly.
It worked for me. I am not sure it is the correct answer. But it solved my problem.
Disclaimer: This is related to another question I asked here. I was advised to ask a new question rather than to update that one, I hope that this is correct. If not please let me know and ignor this question.
I have been trying to use a Neo4j in Microsoft Azure, using this tutorial. I created a VM running Linux and neo4j. I know his works fine because I have been able to access the database via the web admin portal, where I can create and delete entries. However the problem comes when I try to use node.js to insert elements.
Here is the code for the script:
function insert(item, user, request) {
//comment to trigger .js creation
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://<username>:<password>#neo4jmobile.cloudapp.net:7474');
var node = db.createNode({ name: item.name });
node.save(function (err, node) {
if (err) {
console.error('Error saving new node to database:', err);
}
else {
console.log('Node saved to database with id:', node.id);
}
});
request.execute();
}
I am getting this error message:
Error saving new node to database: { [Error: connect ETIMEDOUT]
stack: [Getter/Setter],
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
__frame:
{ name: 'GraphDatabase_prototype__getRoot__1',
line: 76,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev:
{ name: 'GraphDatabase_prototype_getServices__2',
line: 99,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev: [Object],
active: false,
offset: 5,
col: 12 },
active: false,
offset: 5,
col: 12 },
rawStack: [Getter] }
Any help would be appreciated!
Your URL is still wrong: http://<username>:<password>#http://neo4jmobile.cloudapp.net:7474 should be http://<username>:<password>#neo4jmobile.cloudapp.net:7474
In the referenced tutorial (which is quite good btw) he says:
var db = new neo4j.GraphDatabase('http://<username>:<password>#<your neo url>.cloudapp.net:7474');
Where refers to the hostname, i.e.: neo4jmobile