React Native - Failed to parse declaration in styled-components - react-native

The same approach using stylesheet works normally
Environment
System:
OS: macOS 11.6
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU # 2.60GHz
Memory: 1.03 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.6.0 - ~/.nvm/versions/node/v16.6.0/bin/node
Yarn: 1.22.11 - ~/.nvm/versions/node/v16.6.0/bin/yarn
npm: 6.14.4 - ~/Projects/design-system/typography/node_modules/.bin/npm
Watchman: 2021.09.13.00 - /usr/local/bin/watchman
npmPackages:
styled-components: 5.1.0 => 5.1.0
Reproduction
import React from 'react';
import styled from 'styled-components/native';
import { View } from 'react-native';
const CustomText = styled.Text(({ theme }) => ({
fontFamily: 'Zapf Humanist 601',
}));
export default App = () => (
<View>
<CustomText>Your Text<CustomText>
</View>
);
Steps to reproduce
Copy ZapfHumanist601BT-Roman.ttf in your fonts folder (./src/assets/fonts)
Make a link font using npx react-native link
Apply a linked font in your text component
Expected Behavior
The font is expected to be applied in the style
Actual Behavior
Error: Failed to parse declaration "fontFamily: Zapf Humanist 601"

The font-weight property will not work fine in this situation.
You can put your fonts in src/assets/fonts directory:
src
|_ assets
|_ Montserrat-Bold.ttf
|_ Montserrat-Regular.ttf
// and so on for the rest of fonts file
And define the assets properties in the react-native.config.js file which is at the root of your project in this way:
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./src/assets/fonts/'],
};
Now, you can use the fonts in the styles like this (without define the weight property):
title : {
fontFamily: Montserrat-Regular
}

Related

Vue i18n : Pluralization and Linked Messages not interpreted in production

I've managed to integrate nicely the vue-i18n library on my development environment and it works perfectly.
However, when I deploy the project on Heroku, every message using vue-i18n Pluralization or Linked Locale Messages is not being interpreted and shows the entire locale message string :
I've opened a discussion on the repo but no reply so far...
I am using vue-i18n (9.2.2) in a Nuxt3 plugin, therefore using VueJS 3, building with Vite with the plugin for vue-i18n vite-plugin-vue-i18n.
Nuxt3 configuration (nuxt.config.ts), showing the Vite plugin config to resolve the locales JSON files :
import { defineNuxtConfig } from 'nuxt'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'url'
import VueI18nVitePlugin from '#intlify/unplugin-vue-i18n/vite'
export default defineNuxtConfig({
...
vite: {
plugins: [
VueI18nVitePlugin({
include: [
resolve(dirname(fileURLToPath(import.meta.url)), './locales/*.json')
]
})
]
},
...
});
Nuxt plugin for vue-i18n (plugins/vue-i18n.ts) :
import { createI18n } from 'vue-i18n'
import fr from '~/locales/fr.json'
import en from '~/locales/en.json'
// DOC I18N : https://www.i18next.com/translation-function/essentials
export default defineNuxtPlugin(({ vueApp }) => {
const i18n = createI18n({
legacy: false,
allowComposition: true,
globalInjection: true,
locale: 'fr',
fallbackLocale: 'en',
messages: {
'en': en,
'fr': fr,
}
});
vueApp.use(i18n);
})
And here are the 2 locales files :
locales/fr.json :
{
"test": "Zero test | Un test | {n} tests",
"testnested": {
"nestedvalue": "Zero sous-test | Un sous-test | {n} sous-tests"
},
...
locales/en.json :
"test": "Zero test | One test | {n} tests",
"testnested": {
"nestedvalue": "Zero sub-test | Un sub-test | {n} sub-tests"
},
...
}
Example of how the locale messages are used within the Vue templates :
<p>
-- TEST ROOT --<br />
{{ $t('test', 0) }}<br />
{{ $t('test', 1) }}<br />
{{ $t('test', 2) }}<br />
<br />
-- TEST NESTED --<br />
{{ $t('testnested.nestedvalue', 0) }}<br />
{{ $t('testnested.nestedvalue', 1) }}<br />
{{ $t('testnested.nestedvalue', 2) }}<br />
</p>
The Plurals and Linked messages syntax in the locales messages should be interpreted by vue-i18n and not display the full locale message string.
[EXPECTED] Local environment output :
[BUG RESULT] Same code packaged for production, deployed on Heroku :
Another example with failing Linked Messages (in production) :
Here are some infos about my system :
System:
OS: Windows 10 10.0.22000
CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU # 1.30GHz
Memory: 16.35 GB / 31.59 GB
Binaries:
Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22000.120.0),
Chromium (105.0.1343.27)
Internet Explorer: 11.0.22000.120
npmPackages:
#intlify/unplugin-vue-i18n: ^0.5.0 => 0.5.0
vitest: ^0.20.3 => 0.20.3
vue-i18n: ^9.2.2 => 9.2.2
vue-toastification: next => 2.0.0-rc.5
I have read on other threads and on StackOverflow here but the accepted answer doesn't seem to be up-to-date, and believe there could be issues with the way webpack or vite are packaging the project.
What am I doing wrong here ?
If nothing seems wrong, would you recommend I open a bug report on vue-i18n repo ? Or on the #intlify/vite-plugin-vue-i18n repository ?
I had the same problem.
Think this is an issue with the vite-plugin-vue-i18n pre-compile which converts messages to JS functions. I set runtimeOnly:false in vite.config.js and it then worked the same in Production as in HMR.

Expo and metro bundler: external module cannot resolve react import

I configured metro.config.js with the extraNodeModules setting so metro will find my shared modules from outside my project (a 'monorepo' configuration).
Metro is finding my external module (see dumb-module below), but I'm getting an error when that external module tries to import react. I get no error when the imported module does not import react.
Here's the error:
Unable to resolve module #babel/runtime/helpers/interopRequireDefault from /Users/jim/.../modules/dumb-module/index.js: #babel/runtime/helpers/interopRequireDefault could not be found within the project.
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
> 1 | import React from 'react';
2 | import { Text } from 'react-native';
3 |
4 | const DumbModule = () => {
Because it's showing the contents of dumb-module, it's clearly able to find my external modules. But it looks like it can't resolve that module trying to import react.
I've tried, as you might expect, everything. Would love to get some ideas here.
metro.config.js
const path = require('path');
const extraNodeModules = {
'modules': path.resolve(path.join(__dirname, '../../modules'))
};
const watchFolders = [
path.resolve(path.join(__dirname, '../../modules'))
];
const nodeModulesPaths = [path.resolve(path.join(__dirname, './node_modules'))];
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: true,
inlineRequires: true,
},
}),
},
resolver: {
extraNodeModules,
nodeModulesPaths
},
watchFolders
};
dumb-module/index.js
import React from 'react';
import { Text } from 'react-native';
const DumbModule = () => {
return (
<Text>I am useless.</Text>
);
};
export default DumbModule;
expo diagnostics:
expo diagnostics
Expo CLI 4.12.0 environment info:
System:
OS: macOS 11.6
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
Yarn: 1.22.11 - ~/.nvm/versions/node/v14.16.1/bin/yarn
npm: 7.24.0 - ~/.nvm/versions/node/v14.16.1/bin/npm
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
IDEs:
Xcode: 13.0/13A233 - /usr/bin/xcodebuild
npmPackages:
expo: ~42.0.1 => 42.0.4
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2
react-native-web: ~0.13.12 => 0.13.18
npmGlobalPackages:
expo-cli: 4.12.0
Expo Workflow: managed
So, this actually works fine, and my issue was I wasn't resetting the metro cache properly.
I'll leave this post up because this metro.config.js is part of the solution to getting an expo app to work inside a monorepo and utilized shared components.
The other part is using yarn's nohoist option on the expo app folder so its dependencies are kept within its node_modules.

Vuepress multiple sidebar don't show all items

I'm learning about vuepress and i'm trouble to config the sidbar.
Description
Following the docs I replicated the multiple-sidebar configuration without success.
Only the first path it is showed. What am i doing worg?
My config js:
module.exports = {
title: "Jhonatan Morais",
description: "Welcome to my documentation site",
editLinks: true,
smoothScroll: true,
themeConfig: {
sidebar: {
"/foo/": ["", "one"],
"/bar/": ["", "three"],
// fallback
"/": ["" /* / */],
},
},
postcss: {
plugins: [require("autoprefixer"), require("tailwindcss")("./tailwind.js")],
},
};
My project organization
My render results from yarn docs:dev
Some others details
If i browse the pages by url they are there
Here is my system info:
Environment Info:
System:
OS: Windows
CPU: (8) x64 Intel(R) Core(TM) i7-4770 CPU # 3.40GHz
Binaries:
Node: 10.16.2 - C:\Users\JHONAT~1.MOR\AppData\Local\Temp\yarn--1593443655966-0.6783257365479927\node.CMD
Yarn: 1.22.4 - C:\Users\JHONAT~1.MOR\AppData\Local\Temp\yarn--1593443655966-0.6783257365479927\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
#vuepress/core: 1.5.2
#vuepress/theme-default: 1.5.2
vuepress: ^1.5.2 => 1.5.2
npmGlobalPackages:
vuepress: Not Found
I believe this is working as designed. You will only see the /foo/ sidebar when the route starts with /foo/. So, you won't see the /bar/ sidebar until you go to a route/page that starts with /bar/. You may want to use Sidebar Groups if you want to group links together in a single sidebar that is displayed for every route.

Cannot Load fontFamily:FontAwesome in reactnative

I'm build app running in react native metro builder but not running because font family font awesome not sync can help me
problem load is : console error : "fontFamily:FontAwesome" is not a system font in reactnative
i am using the fontawesome 5.7.0
just add on your package dependencies:
"react-native-fontawesome": "^5.7.0",
re-install using yarn
yarn install
put the font files on folder
android > app > src > main > assets > fonts
files:
fontawesome-webfont.ttf
FontAwesome.otf
and you can use it on your project:
example:
import FontAwesome, { Icons } from 'react-native-fontawesome';
...
render() {
return (
<FontAwesome>{Icons.close}</FontAwesome>
);
}

Cross platform component react-native-web

I use react-native-web and I would like to create cross-platform components. I would like to differentiate each components by platform.
So I followed this tutorial: https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
I have 3 files :
     - friendsList.android.js
     - friendsList.ios.js
     - friendsList.web.js
And for import FriendsList, in the index.android.js, index.ios.js index.web.js :
Import FriendsList from './friendsList';
On Ios and Android, it works fine. But on the web, it does not recognize the file. I actually have 3 solutions:
- specify when importing: import FriendsList from './friendsList.web';
- define a service who dispatch for each platform
- or to define an alias in webpack:
resolve: {
alias: {
'react-native': 'react-native-web',
'./friendsList': './friendsList.web',
},
},
Is there a way to import .web without this ways ?
Maybe it's not thought to do like that ?
According to react-native-web getting started documentation, you need to set the extensions.
resolve: {
// Maps the 'react-native' import to 'react-native-web'.
alias: {
'react-native': 'react-native-web'
},
// If you're working on a multi-platform React Native app, web-specific
// module implementations should be written in files using the extension
// `.web.js`.
extensions: [ '.web.js', '.js' ]
}