why getServerSideProps(SSR) doesn't work at vercel deploy - next.js

I am trying to deploying next js instagram clone coding.
so i used the getServerSideProps for singin with google.
it works at localhost:3000 what i want.
but after deploying this web then when i click the signin then turns out server error page.
i don't know what can i do to solve this problem.
i already downgrade firbase to 9.4.0
and i used getStaticProps(?) instead of getServerSideProps..
(if i need to use useeffect instead of getServerSideProps then please show me detail code please.... i am beginner :( )
please help me out
this is signIn code:
import {getProviders, signIn as SignIntoProvider } from "next-auth/react";
import Header from "../../components/Header";
import Image from "next/future/image";
//Brower...
function signIn({providers}){
return (
<>
<Header />
<div className="flex flex-col items-center min-h-screen py-2 mt-56 text-center">
<Image className="w-80" src="/img/스쿼드 로고.png" alt="" width={400} height={200}/>
<p className="font-xs italic">
SQUARD PROJECT - By EunSeo PARK
</p>
<div className='mt-20'>
{Object.values(providers).map((provider) => (
<div key={provider.name}>
<button className="p-3 bg-blue-500 rounded-lg text-white" onClick={() => SignIntoProvider(provider.id, {callbackUrl: "/"})}>
Sign in with {provider.name}
</button>
</div>
))}
</div>
</div>
</>
);
}
//Server side
//export async function getServerSidedProps
export async function getServerSideProps() {
const providers = await getProviders();
if (!providers) {
return {
redirect: {
destination: '/',
permanent: false,
},
}
}
return {
props: {
providers,
},
};
}
export default signIn;
this is the package.json code:
{
"name": "my-project",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"#faker-js/faker": "^7.5.0",
"#headlessui/react": "^1.7.2",
"#heroicons/react": "^1.0.6",
"#tailwindcss/forms": "^0.5.3",
"fake": "^0.2.2",
"faker": "^6.6.6",
"firebase": "^9.4.0",
"moment": "^2.29.4",
"next": "12.3.0",
"next-auth": "^4.10.3",
"next-optimized-images": "^2.6.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-moment": "^1.1.2",
"react-router-dom": "^6.4.1",
"recoil": "^0.7.5",
"tailwind-scrollbar-hide": "^1.1.7",
"typescript": "^4.8.4"
},
"devDependencies": {
"autoprefixer": "^10.4.11",
"eslint": "8.23.1",
"eslint-config-next": "12.3.0",
"postcss": "^8.4.16",
"tailwind-scrollbar": "^2.0.1",
"tailwindcss": "^3.1.8"
}
}
this is the next.config.js code:
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}
const colors = require('tailwindcss/colors')
module.exports = {
images: {
domains: ['localhost', 'images.unsplash.com', 'googleusercontent.com','lh3.googleusercontent.com',
'firebasestorage.googleapis.com', 'googleapis.com','cloudflare-ipfs.com']
},
mode: 'jit',
theme: {
extend: {
colors: {
sky: colors.sky,
cyan: colors.cyan,
},
backgroundColor: ['active'],
},
},
variants: {},
plugins: [],
}

Related

How Laravel 9 works with VueJS 3 on Blade files?

This is some files from my Laravel 5.8 project that has some Vue2 components.
I have created a new fresh installation of Laravel 9, Vue 3 and ViteJS.
Something is wrong and I can't figure out what.
Let's see some code:
The package.json:
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"#popperjs/core": "^2.11.6",
"#vue/compat": "^3.1.0",
"axios": "^1.1.2",
"bootstrap": "^5.2.3",
"laravel-vite-plugin": "^0.7.2",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"sass": "^1.56.1",
"vite": "^3.0.0"
},
"dependencies": {
"#vitejs/plugin-vue": "^3.2.0",
"#vue/compiler-sfc": "^3.1.0",
"fsevents": "^2.3.2",
"jquery": "^3.6.3",
"laravel-echo": "^1.15.0",
"moment-timezone": "^0.5.40",
"pusher-js": "^8.0.1",
"tinymce": "^6.3.1",
"vue": "^3.2.45",
"vue-loader": "^15.10.1",
"vue-moment": "^4.1.0",
"vue-scrollto": "^2.20.0",
"vue-the-mask": "^0.11.1",
"vue-toasted": "^1.1.28"
}
}
The vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '#vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
},
},
});
This is a piece of my app.jsfile:
import Vue from 'vue';
import { createApp } from 'vue';
import UploadForm from './components/UploadForm.vue';
// ...
import './bootstrap';
const app = createApp({
components: {
UploadForm,
// ...
}
})
app.mount('#app')
export const bus = new Vue();
This is a part of < body > section of app.blade.phpfile:
<div id="app">
<div v-if="loader" class="loading" id="loader">Loading…</div>
#include('_inc.nav.topNav')
<main class="m-t-0">
#yield('content')
</main>
</div >
This is part of some.blade.php file:
#extends('layouts.app')
#section('content')
<div class="container m-b-100">
<!-- Content -->
</div>
#endsection
#section('scripts')
<script type="text/javascript" src="{{ asset('js/moment-with-locales.min.js') }}"></script>
<script>
const { createApp } = Vue;
const app = createApp({
el: '#app',
data: {
// some data, methods
}
});
app.mount('#app');
</script>
#endsection
At the Inspector Window the error is:
Uncaught TypeError: t.call is not a function
and it is pointing to:
app.mount('#app');

Tailwind text color shown in blue instead of grey

I am working on a react js project with node and npm as a package manager.
Inside my project I am using multiple packages like heroicons and tailwind.
Inside my footer I want the text to be grey - therefore I am using the "text-slate-500" color inside my Footer.js file.
My result is being shown in blue and underlined, even though I am not using the underline property inside my code.
I am a total beginner with frontend development and also a newbie to tailwind css. So every help is very much appreciated and I am sorry in advance if some information is missing.
Here are the files:
Footer.js
import React from 'react'
import { HomeIcon } from '#heroicons/react/outline'
export const Footer = () => {
return (
<footer className="mx-auto mt-32 w-full max-w-container px-4 sm:px-6 lg:px-8">
<div className="border-t border-slate-900/5 py-10 row-start-auto">
<p className="mt-5 text-center text-sm leading-6 text-slate-500">© {new Date().getFullYear()} Hochschule für angewandte Wissenschaften Würzburg - Schweinfurt</p>
<div className="mt-16 flex items-center justify-center space-x-4 text-sm font-semibold leading-6 text-slate-700">
Datenschutz
<div className="h-4 w-px bg-slate-500/20">
</div>
Impressum
<div className="h-4 w-px bg-slate-500/20"></div>
Barrierefreiheit
<div className="h-4 w-px bg-slate-500/20"></div>
Deutsch - English
</div>
</div>
</footer>
)
}
export default Footer;
package.json
{
"name": "aicard",
"version": "0.1.0",
"private": true,
"dependencies": {
"#headlessui/react": "^1.6.6",
"#heroicons/react": "^2.0.10",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.1.1",
"#testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"bootstrap": "^5.1.3",
"chart.js": "^3.9.1",
"fast-equals": "^4.0.1",
"io": "^1.0.5",
"nodemon": "^2.0.16",
"query-string": "^7.1.1",
"react": "^18.1.0",
"react-chartjs-2": "^4.3.1",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"socket.io-client": "^4.5.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^10.4.8",
"postcss": "^8.4.16",
"tailwindcss": "^3.1.8"
}
}
tailwind.config.js
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {
colors: {
'regal-blue': '#243c5a',
'gameblue': '#1d3f56',
'gamebluehover' : '#122736',
'gamebluelight' : '#244f6b',
'gamebluelightest' :'#326d94',
'fhwsorange' : '#dd742e',
'gameboardconfig' : '#2e4c61',
},
},
},
plugins: [],
}
And this is my result:
Footer.js visualized
Provide classname direct to anchor link and for text-decoration use appropriate class for removing that.
Deutsch - English

Tailwind UI components aren't renderring correctly in Next.js?

I followed the Tailwind UI getting started documentation, but for some reason it looks nothing like it's supposed to in my Next.js project.
Here is my tailwind.config.ts:
export const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
content: ["./src/**/*.{html,js,jsx,ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["Inter var", ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require("#tailwindcss/forms")],
};
Here's my package.json:
{
"name": "nextjs-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"#headlessui/react": "^1.5.0",
"#heroicons/react": "^1.0.6",
"next": "12.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"tailwindcss": "^3.0.23"
},
"devDependencies": {
"#types/node": "17.0.21",
"#types/react": "17.0.40",
"eslint": "8.11.0",
"eslint-config-next": "12.1.0",
"typescript": "4.6.2"
}
}
Here's my _document.tsx:
import Document, { Html, Head, Main, NextScript } from "next/document";
class MyDocument extends Document {
render() {
return (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
rel="stylesheet"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
Here is what the Signin component looks like:
Here's what it should look like:
Add your extra file paths (such as 'components' and 'sections') to tailwind.config.js:
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
// ADD extra paths here...
],
theme: {
extend: {},
},
plugins: [],
}
As shown here - https://tailwindcss.com/docs/guides/nextjs

How to fix "TypeError: rule.assign is not a function" when trying to import ReactToastify.css

I can import { ToastContainer } from 'react-toastify with no problems, but when I try to
import 'react-toastify/dist/ReactToastify.css';, I get an error:
./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[7].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[7].use[2]!./node_modules/react-toastify/dist/ReactToastify.css
TypeError: rule.assign is not a function
I'm using next.js and tailwind css with 'jit' mode enabled.
_app.js:
import 'tailwindcss/tailwind.css';
import '../public/css/syles.css';
import NavBar from '../components/NavBar';
// dynamic(
// () =>
// import('!style-loader!css-loader!react-toastify/dist/ReactToastify.css'),
// { ssr: false } <== tried this as a potential fix, but didn't work.
// );
// import dynamic from 'next/dynamic';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function MyApp({ Component, pageProps }) {
return (
<>
<ToastContainer position='top-center' />
<NavBar />
<Component {...pageProps} />;
</>
);
}
export default MyApp;
package.json:
{
"name": "client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#headlessui/react": "^1.4.2",
"#heroicons/react": "^1.0.5",
"#tailwindcss/line-clamp": "^0.2.2",
"axios": "^0.24.0",
"bootstrap": "^5.1.3",
"express": "^4.17.1",
"heroicons": "^1.0.5",
"http-proxy-middleware": "^2.0.1",
"next": "^12.0.7",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-toastify": "^8.1.0"
},
"devDependencies": {
"autoprefixer": "^10.4.0",
"postcss": "^8.4.3",
"postcss-preset-env": "^7.0.1",
"tailwindcss": "^2.2.19"
}
}
Any suggestions would be appreciated. Thanks.
Ok, so I solved it by { injectStyle } and executing in useEffect().
I referred to this page: https://fkhadra.github.io/react-toastify/how-to-style/#inject-style-on-demand
_app.js:
import 'tailwindcss/tailwind.css';
import '../public/css/syles.css';
import NavBar from '../components/NavBar';
import { useEffect } from 'react';
import { ToastContainer } from 'react-toastify';
import { injectStyle } from 'react-toastify/dist/inject-style';
function MyApp({ Component, pageProps }) {
useEffect(() => {
injectStyle();
}, []);
return (
<>
<ToastContainer position='top-center' />
<NavBar />
<Component {...pageProps} />;
</>
);
}
export default MyApp;

Vue3 css background-image injection

Constructing from my previous question, I would like now to not only inject a variable to my scoped css, but to inject an url image. I've tried several combinations, but none seem to work:
<template>
<header class="header">
</header>
</template>
<script>
import { ref, defineComponent, computed } from 'vue'
export default defineComponent({
components: { },
setup() {
const cssVars = ref()
cssVars.value = {myImage: '"hero-small.jpg"'}
const imageBind = computed(() => '"../../assets/img/hero-small.jpg"')
return {
cssVars,
imageBind,
}
},
})
</script>
<style lang="scss" scoped>
.header {
background-image: url(v-bind(imageBind));
}
</style>
Any tips?
PD: CONFIG FILES:
package.json
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.21.0",
"bootstrap": "^4.5.3",
"core-js": "^3.6.5",
"jquery": "^3.5.1",
"popper.js": "^1.16.1",
"register-service-worker": "^1.7.1",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-pwa": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0",
"#vue/eslint-config-airbnb": "^5.1.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.13.0",
"eslint-plugin-import": "^2.22",
"eslint-plugin-vue": "^7.1.0",
"node-sass": "^5.0.0",
"sass-loader": "^10.1.0"
}
}
jsconfig.json
{
"include": ["./src/**/*"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"#/*": ["./src/*"]
}
}
}
.eslintrc.js
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/vue3-essential',
'#vue/airbnb', // https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base/rules
],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'global-require': 0,
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
// https://eslint.org/docs/rules/prefer-destructuring
'prefer-destructuring': ['error', { object: true, array: false }],
// https://eslint.org/docs/rules/max-len
'max-len': [
'warn',
{
code: 120,
tabWidth: 4,
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
// https://eslint.org/docs/rules/semi
semi: ['off', 'never'],
// https://eslint.org/docs/rules/indent
indent: ['warn', 4],
// https://eslint.org/docs/rules/no-underscore-dangle
'no-underscore-dangle': ['off'],
// https://eslint.org/docs/rules/class-methods-use-this
'class-methods-use-this': ['off'],
// https://eslint.vuejs.org/rules/no-multiple-template-root.html
'no-multiple-template-root': ['off'],
},
overrides: [
{
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
env: {
jest: true,
},
},
],
}
babel.config.js
module.exports = {
presets: ['#vue/cli-plugin-babel/preset'],
}
Try out to require the image :
const imageBind = computed(() => require("../../assets/img/hero-small.jpg"))
then :
<style lang="scss" scoped>
.header {
background-image: url(v-bind(imageBind));
}
</style>
As an alternative to setting the variable dynamically as a CSS class via v-bind(), it's also possible to bind as inline style:
<template>
<header :style="{backgroundImage: `url('$imageUrl')`}"></header>
</template>
See https://vuejs.org/guide/essentials/class-and-style.html#binding-inline-styles

Resources