Where is the config. problem in this Firebase and React App? - reactjs

App is based on 2-year old tutorial at https://www.youtube.com/watch?v=82tZAPMHfT4
Since the tutorial is over 2 years old, I've made config changes that diverge from what is brought up in the tutorial, but I don't seem to be making any headway.
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"webpack": "node_modules/.bin/webpack -d"
},
"engines": {
"node": "8"
},
"dependencies": {
"#babel/preset-env": "^7.7.6",
"#babel/preset-react": "^7.7.4",
"consolidate": "^0.15.1",
"es6-promise": "^4.2.8",
"express": "^4.17.1",
"firebase": "^7.5.0",
"handlebars": "^4.5.3",
"isomorphic-fetch": "^2.2.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"braces": "^3.0.2",
"firebase-admin": "^8.8.0",
"firebase-functions": "^3.3.0",
"firebase-functions-test": "^0.1.6",
"firebase-tools": "^7.9.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
"private": true
}
webpack.config.js
let path = require("path");
let config = {
entry: "./index.js",
module: {
rules: [
{
test: /\.js?/,
loader: "babel-loader",
query: {
presets: ["#babel/react"],
},
},
],
},
output: {
filename: "bundle.js",
path: __dirname + "/public",
},
};
module.exports = config;
.babelrc
{
"presets": ["#babel/preset-react", "#babel/preset-env"],
"compact": false
}
After running npm run webpack, lots of errors of the form:
ERROR in ./node_modules/#google-cloud/firestore/build/protos/protos.json
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/tm/devDir/fbHosting/functions/node_modules/#google-cloud/firestore/build/protos/protos.json: Unexpected token, expected ";" (2:10)
1 | {
> 2 | "nested": {
| ^
3 | "google": {
4 | "nested": {
5 | "firestore": {
And/or:
ERROR in ./node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client_config.json
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/tm/devDir/fbHosting/functions/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client_config.json: Unexpected token, expected ";" (2:14)
1 | {
> 2 | "interfaces": {
| ^
3 | "google.firestore.admin.v1.FirestoreAdmin": {
4 | "retry_codes": {
5 | "idempotent": [

try upgrading I think its still looking for old semi colon format configuration.
npm install firebase-functions#latest --save
npm install firebase-admin#latest --save-exact
npm install -g firebase-tools
this is wrong
/Users/tm/devDir/fbHosting/functions/node_modules/#google-cloud/firestore/build/src/v1/firestore_admin_client_config.json: Unexpected token, expected ";" (2:14)
try
npm install #google-cloud/firestore
Version
2.6.1

Related

Uncaught Error: Module build failed: Cannot find module'#babel/plugin-proposal-class-properties'

I've been trying to deploy this simple app to Heroku and my app works fine when running locally on AWS but when I try to deploy it I get error message:
bundle.js:73 Uncaught Error: Module build failed: Error: Cannot find module '#babel/plugin-proposal-class-properties' from '/app'
at Function.resolveSync [as sync] (/app/node_modules/resolve/lib/sync.js:111:15)
at resolveStandardizedName (/app/node_modules/#babel/core/lib/config/files/plugins.js:101:31)
at resolvePlugin (/app/node_modules/#babel/core/lib/config/files/plugins.js:54:10)
at loadPlugin (/app/node_modules/#babel/core/lib/config/files/plugins.js:62:20)
at createDescriptor (/app/node_modules/#babel/core/lib/config/config-descriptors.js:154:9)
at /app/node_modules/#babel/core/lib/config/config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (/app/node_modules/#babel/core/lib/config/config-descriptors.js:109:29)
at createPluginDescriptors (/app/node_modules/#babel/core/lib/config/config-descriptors.js:105:10)
at /app/node_modules/#babel/core/lib/config/config-descriptors.js:63:49
at cachedFunction (/app/node_modules/#babel/core/lib/config/caching.js:33:19)
at plugins (/app/node_modules/#babel/core/lib/config/config-descriptors.js:28:77)
at mergeChainOpts (/app/node_modules/#babel/core/lib/config/config-chain.js:314:26)
at /app/node_modules/#babel/core/lib/config/config-chain.js:278:7
at buildRootChain (/app/node_modules/#babel/core/lib/config/config-chain.js:68:29)
at loadPrivatePartialConfig (/app/node_modules/#babel/core/lib/config/partial.js:57:55)
at loadPartialConfig (/app/node_modules/#babel/core/lib/config/partial.js:82:18)
at Object.<anonymous> (/app/node_modules/babel-loader/lib/index.js:155:26)
at Generator.next (<anonymous>)
at asyncGeneratorStep (/app/node_modules/babel-loader/lib/index.js:3:103)
at _next (/app/node_modules/babel-loader/lib/index.js:5:194)
at /app/node_modules/babel-loader/lib/index.js:5:364
at Object.<anonymous> (bundle.js:73:7)
at __webpack_require__ (bundle.js:20:30)
at bundle.js:66:18
at bundle.js:69:10
My package.json file looks like this:
{
"name": "Plant-species-app",
"version": "1.0.0",
"description": "Creating a simple CRUD app with NodeJS, MongoDB, GraphQL, React and Apollo",
"main": "index.js",
"scripts": {
"heroku-postbuild": "npm install --production",
"dev": "nodemon index.js --ignore client",
"start": "npm run dev"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-cache-inmemory": "^1.5.1",
"apollo-client": "^2.5.1",
"apollo-link-http": "^1.5.14",
"axios": "^0.15.3",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"body-parser": "^1.16.0",
"connect-mongo": "^1.3.2",
"css-loader": "^0.26.1",
"dotenv": "^16.0.3",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
"express-session": "^1.15.0",
"graphql": "^14.3.0",
"graphql-tag": "^2.10.1",
"html-entities": "^2.3.3",
"html-webpack-plugin": "^2.26.0",
"lodash": "^4.17.4",
"mongoose": "^5.5.7",
"nodemon": "*",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"python": "^0.0.4",
"react": "^16.8.6",
"react-apollo": "^2.5.5",
"react-dom": "^16.8.6",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"style-loader": "^0.13.1",
"webpack": "^2.2.0",
"webpack-dev-middleware": "^1.9.0"
},
"engines": {
"node": "16.17.0",
"npm": "8.15.0"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-proposal-class-properties": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0"
}
}
.babelrc contains:
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
Here is my webpack.config.js:
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './client/index.js',
output: {
path: '/',
filename: 'bundle.js'
},
module: {
rules: [
{
use: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},
{
use: ['style-loader', 'css-loader'],
test: /\.css$/
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'client/index.html'
})
]
};
I'm struggling to figure out where the issue is, I'm assuming it's either in my .bablerc file or webpack.config.js but I also read about the potential difficulty with .babelrc loading here. I'm very new to programming so please excuse my ignorance.
I've tried moving all the babel devdependencies to dependencies in package.json with no change.
I've also tried removing the contents of the .bablerc file with no luck. If I comment out the plugins in the .babelrc file, the same error appears although #babel/plugin-proposal-class-properties is replaced by #babel/preset-env
Can anyone point me in the right direction or explain how to diagnose this issue?
Help would be greatly appreciated

Error on type Props in react flow, converting create-react app to webpack

I am trying to convert a create-react app to a webpack app. The context behind this is that I originally have a app that was made using create-react. I wanted to run that project using webpack. I took an app that I had that was running on webpack, and then I delete all its source files, replacing the with the source files from the create react app. After that, I took package.json dependencies and moved them over from the package.json of the create-react app. I think perhaps I need some extra configuration in webpack to handle flow. I need help in troubleshooting. I get this type of error:
ERROR in ./src/js/constants/Routes.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token, expected ";" (7:5)
5 | import { reduxConnect } from '../hoc';
6 |
> 7 | type Props = {
This is my webpack.config.js:
const path = require('path');
const config = {
entry: __dirname + '/src/js/index.js',
output: {
path: __dirname + '/grails-app/assets/javascripts',
publicPath: '/assets/',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
resolve: {
extensions: [
'.js',
'.jsx'
]
}
};
module.exports = config;
This is my .babelrc
"presets": [
"#babel/preset-env",
"#babel/preset-react"
]
}
package.json (I run in prod mode so ignore devDependencies):
{
"name": "KahuDealerWeb",
"version": "1.0.0",
"description": "Vehicle Finance 3.0 ====================",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"watch": "webpack --watch --colors --progress",
"bundle": "webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ProconGPS/KahuDealerWeb.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/ProconGPS/KahuDealerWeb/issues"
},
"homepage": "https://github.com/ProconGPS/KahuDealerWeb#readme",
"dependencies": {
"#babel/core": "^7.0.1",
"#babel/preset-env": "^7.0.0",
"#babel/preset-flow": "^7.10.1",
"#babel/preset-react": "^7.0.0",
"#material-ui/core": "^4.10.1",
"#material-ui/icons": "^4.9.1",
"axios": "^0.19.0",
"babel-loader": "^8.0.2",
"core-js": "^3.1.3",
"css-loader": "^3.5.3",
"lodash": "^4.17.11",
"material-ui-icons": "^1.0.0-beta.36",
"node-sass": "^4.10.0",
"react": "^16.13.1",
"react-cookies": "^0.1.0",
"react-dom": "^16.13.1",
"react-modal": "^3.11.1",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"react-select": "^2.2.0",
"react-to-print": "^2.5.1",
"recharts": "^1.8.5",
"redux": "^3.7.2",
"redux-observable": "^0.18.0",
"rxjs": "^5.5.6",
"rxjs-compat": "^6.3.3",
"style-loader": "^1.2.1",
"webpack": "^4.18.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
}
}
Flow syntax is not real JS. so things like type Props will fall apart when transpiling or bundling. You need to add a babel plugin/preset to handle these cases.
This is what you're looking to add:
https://babeljs.io/docs/en/babel-preset-flow
But specifically,
Install #babel/preset-flow with either yarn or npm
Then in your .babelrc update your config to add the new preset
{
"presets": [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-flow"
]
}

Module parse failed: Unexpected token using webpack-dev-server

I'm trying to follow along the examples in the Learning Redux book. Unfortunately the latest versions of webpack and babel have all changed and I updated to the latest versions which deviate from the configurations in the book.
I've read the latest documentation from both babel and webpack and I believe I have the correct .babelrc and config.webpack.js that is appropriate.
But I'm struggling to get jsx to compile with the webpack-dev-server. I get this error when running npm start:
ERROR in ./src/index.js
Module parse failed: Unexpected token (10:4)
You may need an appropriate loader to handle this file type.
|
| ReactDOM.render(
| <h1>hello world!</h1>,
| document.getElementById('root')
| )
# multi (webpack)-dev-server/client?http://localhost:8080 ./src
Here is my full setup: https://github.com/homanchou/learning_redux
package.json
{
"name": "learningredux",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "webpack-dev-server --open --mode development",
"build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.7.0",
"webpack": "^4.6.0",
"webpack-cli": "^2.1.2",
"webpack-dev-server": "^3.1.3"
},
"dependencies": {
"npm": "^6.0.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"redux": "^4.0.0"
}
}
babelrc.
{
"presets": ["env", "react"],
"plugins": [ "transform-object-rest-spread" ]
}
config.webpack.js
const path = require('path')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('dist'),
filename: 'main.js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}]
}
}
Any help is appreciated.
You just mixed the order in the config.webpack.js filename.
It needs to be webpack.config.js
Or you need to run webpack with --config and pass the filename.
Everything else should work.

Mocha/ Enzyme doesn't Recognise jsx

My goal is to test reactjs code written with jsx with mocha as test runner, enzyme and chai. Currently I'm getting an unexpectet token error.
I already try the solution inside mocha-will-not-recognise-jsx but it didn't solves my error.
Package.json
{
"scripts": {
"test": "mocha --recursive application/**/*.spec.js* --compilers js:babel-register",
},
[
...
],
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"enzyme": "^2.9.1",
"html-webpack-plugin": "^2.30.1",
"mocha": "^3.5.0",
"standard": "^10.0.3",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
}
}
Webpack modules
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'env']
}
}]
}
Error Message
D:\Development\game-of-life\node_modules\babel-core\lib\transformation\file\index.js:59
0
throw err;
^
SyntaxError: D:/Development/game-of-life/application/src/components/app/App.spec.jsx: U
nexpected token (8:28)
6 | describe('App', () => {
7 | it('renders "<div>Application is running</div>"', () => {
> 8 | const wrapper = shallow(<App />)
| ^
9 | expect(wrapper.contains(<div>Application is running</div>)).to.be.eql(true)
10 | })
11 | })
Did I forgot to install a package or does a newer version of a package works different to an older version of the package because I already realized with equal dependencies a react-enzyme project.
I found two posible ways to solve the problem
.babelrc
Adding a .babelrc with the configureation presets: ['react', 'env'].
webpack
Adding a configuration (babelrc: false) to avoid .babelrc and to use the webpack configuration

unexpected token import during npm start in react

I am learning react and created a mock up project but when I run the project I get the following error,my webpack.config.js file code is as follows,
module.exports = {
entry: './client.js',
output: {
filename: 'bundle.js',
path: 'public'
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}]
}
};
my package.json file,
{
"name": "universal-react",
"version": "0.0.0",
"description": "Universal React web application.",
"scripts": {
"start": "webpack && node server.js",
"dev": "npm-run-all --parallel watch:*",
"watch:webpack": "webpack -w",
"watch:server": "nodemon --ext js,jsx --ignore public/ server.js"
},
"main": "server.js",
"keywords": [
"universal",
"react"
],
"dependencies": {
"babel-core": "^6.9.0",
"babel-loader": "^6.2.4",
"babel-preset-react": "^6.5.0",
"babel-register": "^6.9.0",
"express": "^4.13.4",
"marked": "^0.3.6",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-redux": "^4.4.6",
"react-router": "^2.8.1",
"redux": "^3.6.0",
"webpack": "^1.13.1"
},
"devDependencies": {
"nodemon": "^1.11.0",
"npm-run-all": "^3.1.2"
}
}
error message is as follows,
/home/user/Documents/test/src/routes/index.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at loader (/home/user/Documents/src/node_modules/babel-register/lib/node.js:144:5)
Could anyone suggest me where i am wrong?
You have not installed babel-preset-es2015 as per your package.json.
"babel-preset-es2015": "^6.9.0",
try installing it via
npm install --save babel-preset-es2015
Also add
"babel": "^6.5.2",
"babel-cli": "^6.9.0"
and a .babelrc file in project root parallel to your package.json
with following content.
$ cat .babelrc
{
"presets": [
"es2015",
"react"
]
}
and then run npm install then webpack again.

Resources