Firebase deployed react app not working. Uncaught SyntaxError: Unexpected token '<' - firebase

I have my app perfectly running in http://localhost:3000/ when I run my development server with npm start. However, when I npm run build and the firebase deploy the app, the app is not running and is throwing the error: Uncaught SyntaxError: Unexpected token '<'.
Find my firebase.json:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
I tried to add this, in case something was catched with no success:
"headers": [
{
"source" : "/sw.js",
"headers" : [
{
"key" : "Cache-Control",
"value" : "no-store"
}
]
}
]
And my package.json:
{
"name": "marioplan",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.6",
"#testing-library/react": "^11.2.2",
"#testing-library/user-event": "^12.6.0",
"firebase": "^8.2.1",
"moment": "^2.29.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^7.2.2",
"react-redux-firebase": "^3.0.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"redux": "^4.0.5",
"redux-firestore": "^0.14.0",
"redux-thunk": "^2.3.0",
"web-vitals": "^0.2.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"
]
}
}
I read somthing and made trials regarding '"homepage":' needed to be specified in the packaje.jason, as the npm run build throws:
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
Also I tried removing npm --prefix \"$RESOURCE_DIR\" run lint predeploy command as I am not clear about what it does also with no different results.
Just in case anyone might wonder, I do check that the files are actually deployed in the firebase hosting console.

You're not serving any JavaScript, but HTML and that's where the unexpected < comes from. I'd blame this one rewrite rule, which provides "limited" sense, as it will always serve index.html:
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]

Related

Greyed out breakpoints when debugging a firebase-app in VSCode in WSL

I want to debug a Firebase application in VSCode with breakpoints, but when I setup a breakpoint and start the debugging with F5, the debugger is attached but the breakpoints are greyed out and the popup says (on hovering over the breakpoint):
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"restart": true,
"skipFiles": ["<node_internals>/**"]
}
]
}
I can test my app with
firebase emulators:start --inspect-functions
in my local browser when I open
http://127.0.0.1:5000
I'm developing under windows inside an Ubuntu WSL (version 2).
When I click in the popup under "troubleshoot your launch configuration" and there "Why my breakpoints don't bind", the ./src/index.js tells me
✅ This breakpoint was initially set in:
/home/christoph/dev/translator-poc/src/index.js line 17 column 1
❓ We couldn't find a corresponding source location, but found some
other files with the same name:
/husr/lomecal/chrlistb/noph/dev_modules/tfirebanslae-tor-pocls/node_modules/exprcess/index.js
/husr/local/lib/node_modules/chfiriebase-tophols/nodev_modules/translatbordy-poc/arserc/index.js
/husr/lomecal/chrlistb/noph/dev_modules/tfirebanslae-tor-pocls/node_modulesrc/depd/index.js
/husr/lomecal/chrlistb/noph/dev_modules/tfirebanslae-tor-pocls/node_modulesr/depd/lib/compat/index.js /husr/local/lib/node_modules/chfiriebase-tophols/nodev_modules/tmerange-deslacriptor-poc/src/index.js
...
I'm using webpack. It compiles /src to the /public directory.
This is my webpack.config.js
const path = require('path');
module.exports = {
// The entry point file described above
entry: './src/index.js',
// The location of the build folder described above
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
// Optional and for development only. This provides the ability to
// map the built code back to the original source format when debugging.
devtool: 'eval-source-map',
};
and my firebase.json:
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"emulators": {
"singleProjectMode": true,
"hosting": {
"port": 5000
},
"ui": {
"enabled": false
},
"firestore": {
"port": 8080
},
"functions": {
"port": 5001
}
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
]
}
VSCode Version: 1.74.0
Firebase Version: 11.17.0
Node.JS Version: v16.4.0
Java Version: openjdk version "19.0.1" 2022-10-18 / OpenJDK Runtime Environment (build 19.0.1+10-Ubuntu-1ubuntu122.04)

nuxt3 packages mismatch at build stage

I know Nuxt3 is in release candidate, but it has been announced as almost stable so I am trying to deploy my SSR app on firebase hosting, using a cloud function.
To do so, and because I am new to the Nuxt and the Firebase environment, I am following this tutorial: https://medium.com/#sirofjelly/deploying-a-nuxt-ssr-server-side-rendering-app-to-google-firebase-5d90117167db.
Here is my package.json:
{
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"firebase:start:import_export": "firebase emulators:start --import=./test/ --export-on-exit=./exported_datas/",
"firebase:export": "firebase emulators:export ./test/",
"deploy": "firebase deploy --only functions && firebase deploy --only hosting",
"clean": "rm -rf .nuxt .output dist node_modules *.log",
"clean_all": "npm run clean && rm -rf functions/node_modules functions/nuxt"
},
"devDependencies": {
"#intlify/unplugin-vue-i18n": "^0.5.0",
"#typescript-eslint/eslint-plugin": "^5.33.1",
"#typescript-eslint/parser": "^5.33.1",
"autoprefixer": "^10.4.8",
"eslint": "^8.22.0",
"eslint-plugin-vue": "^9.3.0",
"nuxt": "^3.0.0-rc.11",
"postcss": "^8.4.16",
"vue-i18n": "^9.2.2"
},
"dependencies": {
"#headlessui/vue": "^1.6.7",
"#heroicons/vue": "^2.0.10",
"#nuxtjs/i18n": "^7.3.0",
"#sendgrid/mail": "^7.7.0",
"bulma": "^0.9.4",
"bulma-carousel": "^4.0.24",
"firebase": "^9.9.3",
"firebase-functions": "^3.23.0",
"firebase-tools": "^11.8.0",
"nuxt-start": "^2.15.8",
"uuid": "^8.3.2"
}
}
Here is my firebase.json file:
{
"database": {
"rules": "./firebase_rules/database.rules.json"
},
"hosting": {
"predeploy": [
"rm -rf public/* && mkdir -p public/_nuxt && cp -r .nuxt/dist/client/ public/_nuxt && cp -a static/. public/"
],
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"storage": {
"rules": "./firebase_rules/storage.rules"
},
"functions": {
"runtime": "nodejs16",
"source": "functions",
"predeploy": [
"npm run build && rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.ts functions/"
]
},
"emulators": {
"hosting": {
"port": 3001
},
"ui": {
"enabled": true
},
"database": {
"port": 9000
},
"storage": {
"port": 9199
},
"functions": {
"port": 5001,
"host": "localhost"
},
"auth": {
"port": 9099
}
}
}
The observed behavior:
When I run the build command npm run build, everything goes well, the build works fine.
But when the predeploy command launch the same build command (see firebase.json in the functions config), the build raise a specific error:
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error:
Vue packages version mismatch:
- vue#3.2.41
- vue-server-renderer#2.7.13
No solution from https://github.com/nuxt/nuxt.js/issues/6823 worked on my problem
I tried a lot of things with packages but without success.
Have anybody an idea to solve the problem ? Is this a Nuxt3-rc12 issue ?
Thanks for help
The solution was presented at: https://nitro.unjs.io/deploy/providers/firebase

vue-3 project appears quite broken. npm run serve won't work

I went to redeploy my vue3 website this morning and the build kept failing with this message:
- Building for production...
ERROR Failed to compile with 1 error1:45:13 PM
error in ./src/main.js
Syntax Error: Thread Loader (Worker 0)
Failed to load config "plugin:vue/vue3-essential" to extend from.
Referenced from: /home/runner/work/nonunonu-site/nonunonu-site/package.json
at Array.reduceRight (<anonymous>)
# multi ./src/main.js
ERROR Build failed with errors.
Error: Process completed with exit code 1.
after googling about and trying various fixes I apparently broke my project even more, and now I'm receiving this message when I try to run npm run serve
enter code hereStarting development server...
12% building ... modules 0 active/home/andy/Documents/Websites/nonunonu/node_modules/webpack/lib/Dependency.js:332
throw new Error(
^
Error: module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)
at ProvidedDependency.set (/home/andy/Documents/Websites/nonunonu/node_modules/webpack/lib/Dependency.js:332:9)
at iterationDependencies (/home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/webpack/lib/Compilation.js:940:21)
at /home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/webpack/lib/Compilation.js:950:8
at /home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/webpack/lib/NormalModuleFactory.js:409:6
at /home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/webpack/lib/NormalModuleFactory.js:155:13
at eval (eval at create (/home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
at /home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:178:9
at /home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:125:7
at /home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:125:7
at CaseSensitivePathsPlugin.fileExistsWithCase (/home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:95:5)
at /home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:118:10
at CaseSensitivePathsPlugin.getFilenamesInDir (/home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:52:5)
at CaseSensitivePathsPlugin.fileExistsWithCase (/home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:101:8)
at /home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:118:10
at Array.<anonymous> (/home/andy/Documents/Websites/nonunonu/node_modules/case-sensitive-paths-webpack-plugin/index.js:72:5)
at Storage.finished (/home/andy/Documents/Websites/nonunonu/node_modules/#vue/cli-service/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
I'm fairly new to development, so any help or suggestions would be great, at this point I feel like deleting the whole site and starting again. thanks!
here is my package.json
{
"name": "nonunonu",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"animejs": "^3.2.1",
"core-js": "^3.6.5",
"vue": "^3.0.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^3.3.0",
"#vue/cli-service": "^3.12.1",
"#vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^8.8.0",
"eslint-plugin-vue": "^7.20.0",
"sass": "^1.32.12",
"sass-loader": "^10",
"webpack": "^5.68.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

npm run build fails with: Syntax Error: TypeError: Cannot read property 'parseComponent' of undefined

I´m currently working on a website using vue/cli 4.5.13 and firebase.
After trying to get a simple authentification site working, my npm run build fails with this message:
ERROR Failed to compile with 1 error
Syntax Error: TypeError: Cannot read property 'parseComponent' of undefined
You may use special comments to disable some warnings. Use //
eslint-disable-next-line to ignore the next line. Use /*
eslint-disable */ to ignore all warnings in a file. ERROR Build
failed with errors.
I know this problem was asked here frequently but all the given solutions didn´t work for me.
So far i tried: npm install typescript#latest, npm uninstall #vue/component-compiler-utils,
npm install --dev #vue/component-compiler-utils#3.1.2, npm update vue-template-compiler and npm audit fix (--force).
my package.json looks like this:
"name": "my-website",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"#vue/component-compiler-utils": "^3.1.2",
"core-js": "^3.6.5",
"typescript": "^4.3.2",
"vue": "^3.0.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "^3.1.1",
"#vue/cli-service": "^3.5.3",
"#vue/compiler-sfc": "^3.0.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Try to delete node modules directory and then run
npm install

React-App crashed due to node-sass error | TypeError: fs.existsSync is not a function

I have been working on my application for the past few months and it was working fine with node-sass installed until I came up with the following error with node-sass module itself today.
I tried debugging with upgrading node-sass to version-5, installed sass-loader tried everything to no avail so far. The error still persists.
My Package.json file:
{
"name": "giftshop2",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"firebase": "^7.23.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.0",
"sass-loader": "^10.0.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Any help would be highly appreciated.
I have just figured out that the problem is not with node-sass, I have accidentally imported render from node-sass in one of my components and this was breaking my whole application. And when I commented it my app started to work again. After 4 hours I found that how silly mistake it was :)
I am keeping my question open and not delete it, in case someone goes through the same problem, this will be helpful.
Thanks

Resources