Blank screen react-native-paper web
I followed all the documentation to try to configure react-native-paper to run in the browser too. Unsuccessfully.
At the beginning I was facing a lot of compilation errors, I adjusted the modules to resolve these errors and got to the point where I no longer had any errors. The site loads, you can see all the index.html code, just as it is in the documentation. And the app.bundle.js file is also loaded, I can see it in the resources tab.
However, there is only a white screen. I've tried everything to solve this problem, has anyone experienced this? Do you have any idea how to solve it?
Here are my codes that can help:
App.tsx
import React from 'react';
import { Platform, SafeAreaView, StyleSheet, Text, View } from 'react-native';
import { PaperProvider } from 'react-native-paper';
function App(): React.JSX.Element {
return (
<PaperProvider>
<SafeAreaView style={styles.safeAreaView}>
{Platform.OS === 'web' ? (
<style type="text/css">{
@font-face {
font-family: 'MaterialCommunityIcons';
src: url(${require('react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf')}) format('truetype');
}
}</style>
) : null}
{/* <AppStack /> */}
<View
style={{
display: 'flex',
flex: 1,
backgroundColor: '#f0f',
width: '100%',
height: '100%',
}}
>
<Text>Just a test</Text>
</View>
</SafeAreaView>
</PaperProvider>
// <View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
// <Text>Just a test</Text>
// </View>
);
}
export default App;
const styles = StyleSheet.create({
safeAreaView: {
flex: 1,
},
});
webpack.config.js
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
module.exports = {
mode: 'development',
// Path to the entry file, change it according to the path you have
entry: path.join(__dirname, 'App.tsx'),
// Path for the output files
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.bundle.js',
},
// Enable source map support
devtool: 'source-map',
// Loaders and resolver config
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules[/\\](?!react-native-vector-icons)/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
'@babel/preset-env',
'@babel/preset-react',
'module:metro-react-native-babel-preset',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'react-native-web',
],
},
},
},
{
test: /\.(ts|tsx|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['module:metro-react-native-babel-preset'],
plugins: [['react-native-web', { commonjs: true }]],
},
},
},
{
test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/,
type: 'asset/resource',
},
],
},
resolve: {
extensions: ['.web.js', '.js', '.jsx', '.ts', '.tsx'],
alias: {
'react-native$': 'react-native-web',
'../Utilities/Platform': 'react-native-web/dist/exports/Platform',
'../../Utilities/Platform': 'react-native-web/dist/exports/Platform',
'./Platform': 'react-native-web/dist/exports/Platform',
'@': path.resolve(__dirname, './src/'),
},
},
// Development server config
devServer: {
static: path.join(__dirname, 'public'),
compress: true,
// historyApiFallback: true,
},
};
babel.config.js
module.exports = (api) => {
const babelEnv = api.env();
const plugins = [
['react-native-web'],
['module:react-native-dotenv'],
[
'module-resolver',
{
root: ['./'],
alias: {
'^@/(.+)': './src/\\1',
'^react-native$': 'react-native-web',
},
extensions: [
'.ios.js',
'.android.js',
'.js',
'.jsx',
'.json',
'.tsx',
'.ts',
'.native.js',
],
},
],
];
if (babelEnv === 'production') {
plugins.push('transform-remove-console');
}
return {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-typescript',
],
plugins,
};
};
Blank screen react-native-paper web
I followed all the documentation to try to configure react-native-paper to run in the browser too. Unsuccessfully.
At the beginning I was facing a lot of compilation errors, I adjusted the modules to resolve these errors and got to the point where I no longer had any errors. The site loads, you can see all the index.html code, just as it is in the documentation. And the app.bundle.js file is also loaded, I can see it in the resources tab.
However, there is only a white screen. I've tried everything to solve this problem, has anyone experienced this? Do you have any idea how to solve it?
Here are my codes that can help:
App.tsx
webpack.config.js
babel.config.js