Why am I getting undefined with i18next handlebars - handlebars.js

I am getting an undefined variable name using i18next with handlebars
Following is my code to init i18next with this package:
const i18next = require('i18next');
const HandlebarsI18n = require("handlebars-i18n");
import resources from "./i18n/messages";
i18next.init({
resources,
debug: true,
fallbackLng: "en",
lng : "en"
});
HandlebarsI18n.init();
export default i18next;
In my index.ts where I have the handlebars compiled I have
import "./i18n"
Where I use the i18next looks like this:
<span class="typography-h3">{{__ getNodeLabel .}}{{#if attributes.required}}
<span class="required-indicator">*</span>{{/if}}
</span>
If I replace the {{__ getNodeLabel .}} with something like {{__ "Password"}} I still get undefined not to sure what is up.

I believe the issue has to do with the i18next peerDependency defined in the package.json of the handlebars-i18n package. In the latest version of handlebars-i18n, the i18next peerDependency version is ^21.6.14.
Assuming you have recently installed i18next into your own project with the command npm install i18next, you will have a dependency in your project's package.json for i18next with the latest version which is currently ^21.9.2.
I am not an expert on how npm handles peerDependencies, but it seems that due to the differences between these two versions, ^21.6.14 and ^21.9.2, that npm is installing both.
This means that in your project's node_modules folder there are two versions of i18next - one at the top-level of your node_modules (21.9.2) and one at node_modules/handlebars-i18n/node_modules (21.6.14).
Its the two versions that cause the problem. When you initialize i18next by calling i18next in your code, you are initializing the 21.9.2 version. But handlebars-i18n loads the 21.6.14 version and it never gets initialized and all calls to its translate, .t, method return undefined.
I was able to get this working by uninstalling i18next and then installing it again using the same version that is defined in the handlebars-i18n package.json:
npm uninstall i18next
npm install i18next#21.6.14
This ensures that only one i18next is installed.

Related

Strapi: Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined

I am trying to install a fresh Strapi app on my mac, by running the
npx create-strapi-app#latest my-project --quickstart
commnand. It installs the Strapi app fine, but when I try to run "npm run develop", I get this error:
"Strapi: Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined."
And the app doesn't start. full error text is as follows:
Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined.
Error: Middleware "strapi::body": Cannot destructure property 'config' of 'strapi.plugin(...)' as it is undefined.
at instantiateMiddleware (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/middleware.js:12:11)
at resolveMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/middleware.js:56:18)
at registerApplicationMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/register-middlewares.js:66:29)
at async Object.initMiddlewares (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/services/server/index.js:99:7)
at async Strapi.bootstrap (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:445:5)
at async Strapi.load (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:457:5)
at async Strapi.start (/Users/davit/Github/my-project/node_modules/#strapi/strapi/lib/Strapi.js:198:9)
Would appreciate any help regarding this issue.
Got the same exception when yarn develop.
Make sure you have right version range for node
node -v if not use nvm use 14.19.1 (or above)
Go to package.json and change strapi version.
from "#strapi/strapi": "^4.3.5" to "#strapi/strapi": "^4.3.6"
Remove package-lock.json and yarn.lock
Run npm install or/and yarn install
I had also posted this question in Strapi forums and it turns out that the problem was with Strapi 4.3.5. They advised updating to 4.3.6 as this issue had been hotfixed. I can confirm that this issue no longer exists on Strapi 4.3.6.

Angular ERROR: PostCSS received undefined instead of CSS string

Trying to build an Angular project and I'm getting the errors below. This project built fine last week. I made some changes to other projects that use the Dlls from this project, but no changes to this project. I already spent a lot of time troubleshooting it with no luck and appreciate any help.
ERROR: PostCSS received undefined instead of CSS string
An unhandled exception occurred: PostCSS received undefined instead of CSS string
This can sometimes happen if node-sass was compiled for a different version of Node.js than you're currently running (ie if you've recently changed your Node.js version). You can fix that with:
npm rebuild node-sass
if you are using webpack, and trying to use sass-loader, also add sass
I had this same issue when attempting to test an Angular library, and the issue was I had [``] instead of [] in the styles property of my component metadata.
Wrong
#Component({
selector: 'my-input',
template: `
<input
... />
`,
styles: [``],
Right
#Component({
selector: 'my-input',
template: `
<input
... />
`,
styles: [],
I had similar problem. I was trying to build an angular library and the message below appeared:
Building Angular Package
------------------------------------------------------------------------------
Building entry point 'library-name'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: PostCSS received undefined instead of CSS string
An unhandled exception occurred: PostCSS received undefined instead of CSS string
See "/tmp/ng-itlEgm/angular-errors.log" for further details.
[12:03:38] 'compile' errored after 17 s
[12:03:38] Error: Command `ng build library-name --prod` exited with code 127
at ChildProcess.handleSubShellExit (/node_modules/gulp-run/command.js:166:13)
at Object.onceWrapper (events.js:422:26)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.EventEmitter.emit (domain.js:505:15)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
[12:03:38] 'build' errored after 17 s
I was using gulp-run to execute the command ng build library-name --prod. But, executing the command ng build library-name --prod directly on the terminal, the log error was smaller, but similar too.
The problem was in one component. The component had one styleURL (Angular component decorator), like this:
...component.css
but, the library uses scss. So, I changed the path to:
...component.scss
and I executed the command 'ng build library-name --prod'. So, the error didn't appear again.
I was using NVM v0.35.2 (allow to have more than one NodeJS version installed in my machine); NodeJS v12.18.2; Ubuntu x64 18.0.4 LTS and Angular CLI 9.1.9.
I faced the same situation now and the command that helped me is -
npm i node-sass -D
Check the node version, see if the version of node changes cause this problem. I use node version 16.14.2 which occured this error, after switch to 12.16.1 it works well. Just check your node-sass and node version will find a way out.
This can happen due to change in version of node. I had same issue with a NUXT app. What I did was
using yarn, in the root directory of your project, run yarn. But if you're using npm run npm install
start your project again.

error using moment.js with serverless-bundle

how can I add moment.js locale file to serverless bundle?
Thanks for any help :)
I tried the following:
git clone git#github.com:AnomalyInnovations/serverless-nodejs-starter.git
cd serverless-nodejs-starter
npm i moment
then in file handler.js add
import moment from "moment";
and update hello with just call to moment(); (to avoid lint error)
when running local run:
serverless invoke local --function hello
the error received:
Error: Cannot find module './locale'
There seems to be an issue with the latest version of momentjs as you can see in this Github Issue. You can try the following:
npm install --save moment#2.24.0
Add a resolutions block in your package.json file as such:
"resolutions": {
"moment": "2.24.0"
}

Vuejs2 firebase with electron error

I have configured electron with vuejs and i would like to add firebae to my project so i have
In my main.js
import * as firebase from 'firebase'
let firebasconfig = {
//config from firebase project
};
Vue.prototype.$firebase = firebase.initializeApp(firebasconfig);
But now am getting an error
Error: Failed to load gRPC binary module because it was not installed
for the current system
Expected directory: electron-v1.8-linux-x64-glibc
Found: [node-v59-linux-x64-glibc]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module
I have tried running rebuild but still fails
What elese do i need to do for this to work
I encouter the same issue with
vue-electron 1.0.6
firebase 5.4.2
vuefire 1.4.5
node 6.10.3
The following manipulation has worked for me. I have downgraded :
firebase to 4.6.0
vuefire to 1.4.4
Then ran npm rebuild and yarn and now it works.
I'm not sure all the things I have done are necessary. But for sure it looks like a problem with firebase.

vue + meteor not compiling after npm update today - 'mapState' is readOnly

I decided to upgrade my modules after updating my mongo engine to wiredtiger. Suddenly the compiler is throwing strange readOnly errors - not only with vuex imports, but components. Here is my console output:
=> Errors prevented startup:
While building for web.browser:
imports/vue/root.vue:70: [vue-component] Error while compiling in tag
<script> col:66: C:/src/app/imports/vue/root.vue:
"mapState" is read-only
imports/vue/home.vue:5: [vue-component] Error while compiling in tag
<script> col:62: C:/src/app/imports/vue/home.vue:
"mainmap" is read-only
imports/vue/login.vue:7: [vue-component] Error while compiling in tag
<script> col:68: C:/src/app/imports/vue/login.vue:
"Template" is read-only
imports/vue/logout.vue:5: [vue-component] Error while compiling in tag
<script> col:73: C:/src/app/imports/vue/logout.vue:
"users" is read-only
Note that I am using the "vue": "git://github.com/mitar/vue.git#meteor", fork of vue in my package.json. Using a stack from the /meteor-vue/vue-meteor github project.
Appreciate any help!
This turned out to be a meteor package version issue. Reverting my meteor versions file to previous state solved it.

Resources