Cannot build node modules when deploying React app to Heroku - node.js

Before I start I should state I've only been coding for 6months, so please forgive any rookie mistakes.
THE PROBLEM: I have been following this simple article on building a personal website with React.js, webpack and a node.js server. This is my first ever React project and the development phase has gone well enough. However, I have not been able to complete the last step outlined in the article i.e. building and deploying my application on Heroku.
The app works fine when I run it locally, so I assume the problem has something to do with the way I have configured the app for Heroku.
COMMAND LINE ERROR: With my Heroku remote ready to receive my app, I attempted to push my latest commit and received the following command line error:
$ git push heroku master ‹ruby-2.4.2›
Counting objects: 488, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (467/467), done.
Writing objects: 100% (488/488), 3.87 MiB | 463.00 KiB/s, done.
Total 488 (delta 252), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=false
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 8.9.1
remote: engines.npm (package.json): 5.6.0
remote:
remote: Resolving node version 8.9.1...
remote: Downloading and installing node 8.9.1...
remote: Bootstrapping npm 5.6.0 (replacing 5.5.1)...
remote: npm 5.6.0 installed
remote:
remote: -----> Restoring cache
remote: Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > uglifyjs-webpack-plugin#0.4.6 postinstall/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/uglifyjs-webpack-plugin
remote: > node lib/post_install.js
remote:
remote:
remote: > cwebp-bin#4.0.0 postinstall/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/cwebp-bin
remote: > node lib/install.js
remote:
remote: ✔ cwebp pre-build test passed successfully
remote:
remote: > gifsicle#3.0.4 **strong text**postinstall/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/gifsicle
remote: > node lib/install.js
remote:
remote: ✔ gifsicle pre-build test passed successfully
remote:
remote: > mozjpeg#5.0.0 postinstall /tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg
remote: > node lib/install.js
remote:
remote: ⚠ The `/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor/cjpeg` binary doesn't seem to work correctly
remote: ⚠ mozjpeg pre-build test failed
remote: ℹ compiling from source
remote: ✖ Error: autoreconf -fiv && ./configure --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor" --bindir="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor" --libdir="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor" && make -j2 && make install -j2
remote: Command failed: ./configure --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor" --bindir="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor" --libdir="/tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/mozjpeg/vendor"
remote: configure: error: no nasm (Netwide Assembler) found
remote:
remote: at ChildProcess.exithandler (child_process.js:275:12)
remote: at emitTwo (events.js:126:13)
remote: at ChildProcess.emit (events.js:214:7)
remote: at maybeClose (internal/child_process.js:925:16)
remote: at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
remote:
remote: > optipng-bin#3.1.4 postinstall /tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/optipng-bin
remote: > node lib/install.js
remote:
remote: ✔ optipng pre-build test passed successfully
remote:
remote: > pngquant-bin#3.1.1 postinstall /tmp/build_7ea60020ff551b38876501f2f9a41fe5/node_modules/pngquant-bin
remote: > node lib/install.js
remote:
remote: ✔ pngquant pre-build test passed successfully
remote:
remote: > personalsite#1.0.0 postinstall /tmp/build_7ea60020ff551b38876501f2f9a41fe5
remote: > webpack
remote:
remote: Hash: c97c97d674d97406c5d6
remote: Version: webpack 3.10.0
remote: Time: 2871ms
remote: Asset Size Chunks Chunk Names
remote: bundle.js 1.26 MB 0 [emitted] [big] main
remote: [114] ./react-client/src/index.js 477 bytes {0} [built]
remote: [125] ./react-client/src/Components/App.js 2.77 kB {0} [built]
remote: [151] ./react-client/src/Components/HomePage.js 4.01 kB {0} [built]
remote: [152] ./react-client/src/Components/About.js 2.61 kB {0} [built]
remote: [153] ./react-client/src/Components/Bio.js 4.38 kB {0} [built]
remote: [154] ./react-client/src/images/bruges.jpg 162 bytes {0} [built] [failed] [1 error]
remote: [155] ./react-client/src/Components/Experience.js 11.5 kB {0} [built]
remote: [160] ./react-client/src/Components/Contact.js 3.1 kB {0} [built]
remote: [161] ./react-client/src/Components/Form.js 4.93 kB {0} [built]
remote: [163] ./react-client/src/Components/Landing.js 3.71 kB {0} [built]
remote: [234] ./react-client/src/Components/ScrollArrow.js 2.54 kB {0} [built]
remote: [236] ./react-client/src/Components/Footer.js 3.32 kB {0} [built]
remote: + 225 hidden modules
remote:
remote: ERROR in ./react-client/src/images/bruges.jpg
remote: Module build failed: Error: write EPIPE
remote: at _errnoException (util.js:1024:11)
remote: at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)
remote: # ./react-client/src/Components/About.js 45:72-103
remote: # ./react-client/src/Components/HomePage.js
remote: # ./react-client/src/Components/App.js
remote: # ./react-client/src/index.js
remote:
remote: ERROR in ./react-client/src/Components/HomePage.js
remote: Module not found: Error: Can't resolve './Navbar.js' in '/tmp/build_7ea60020ff551b38876501f2f9a41fe5/react-client/src/Components'
remote: # ./react-client/src/Components/HomePage.js 33:14-36
remote: # ./react-client/src/Components/App.js
remote: # ./react-client/src/index.js
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 2
remote: npm ERR! personalsite#1.0.0 postinstall: `webpack`
remote: npm ERR! Exit status 2
remote: npm ERR!
remote: npm ERR! Failed at the personalsite#1.0.0 postinstall script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /app/.npm/_logs/2018-01-30T17_48_44_618Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to oliverpoplepersonalwebsite.
remote:
To https://git.heroku.com/oliverpoplepersonalwebsite.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/oliverpoplepersonalwebsite.git'
WHAT I'VE TRIED:
i) I tried installing the npm-shrinkwrap, to see whether locking-in the dependencies would help. It did not.
ii) I also changed Heroku's default configuration from 'NPM_CONFIG_PRODUCTION=true' to 'NPM_CONFIG_PRODUCTION=false', as I wanted devDependencies includes with the node modules installed on Heroku.
Any help would be massively appreciated.
OTHER RELEVANT FILES:
package.json
{
"name": "personalsite",
"version": "1.0.0",
"engines": {
"node": "8.9.1",
"npm": "5.6.0"
},
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack -d - watch",
"start": "node ./server/index.js",
"build": "webpack -p",
"react-dev": "webpack -d --watch",
"server-dev": "nodemon server/index.js",
"postinstall": "webpack",
"heroku-postbuild": "webpack -p"
},
"repository": {
"type": "git",
"url": "git+https://github.com/oliverpople/PersonalSite.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/oliverpople/PersonalSite/issues"
},
"homepage": "https://github.com/oliverpople/PersonalSite#readme",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"body-parser": "^1.18.2",
"dotenv": "^4.0.0",
"express": "^4.16.2",
"foobar": "^1.1.0",
"jquery": "^3.3.1",
"nodemailer": "^4.4.2",
"react": "^16.2.0",
"react-delay-render": "^0.1.2",
"react-dom": "^16.2.0",
"react-event-timeline": "^1.4.1",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-typewriter": "^0.4.1",
"semantic-ui-react": "^0.77.2",
"webpack": "^3.10.0"
},
"devDependencies": {
"file-loader": "^1.1.6",
"image-webpack-loader": "^4.0.0"
}
}
webpack.config.js
const path = require('path');
const SRC_DIR = path.join(__dirname, '/react-client/src');
const DIST_DIR = path.join(__dirname, '/react-client/dist');
const webpack = require('webpack');
module.exports = {
entry: `${SRC_DIR}/index.js`,
output: {
path: DIST_DIR,
filename: 'bundle.js',
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.css']
},
module : {
loaders : [
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
},
},
],
},
{
test: /\.jsx?$/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
presets: ['es2015', "stage-0", 'react']
}
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
};
Components/About.js
import React, { Component } from 'react';
import Bio from "./Bio.js";
class About extends Component {
render() {
return (
<div className='titleContainer' id='aboutSection'>
<div className='titleText'>
ABOUT ME
</div>
<img className='image' src={require("../images/bruges.jpg")} />
<Bio />
</div>
)
}
}
export default About;
Components/NavBar.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Sticky } from 'semantic-ui-react';
class NavBar extends Component {
render() {
return (
<Sticky >
<header>
<span className="navButton" id="homeButton">
<Link to="/#section1" className="navLink">
HOME
</Link>
</span>
<span className="navButton">
<Link to="/#section4" className="navLink">
CONTACT
</Link>
</span>
<span className="navButton">
<Link to="/#section3" className="navLink">
EXPERIENCE
</Link>
</span>
<span className="navButton">
<Link to="/#section2" className="navLink">
ABOUT
</Link>
</span>
</header>
</ Sticky>
)
}
}
export default NavBar;

Related

Having problems to deploy to Heroku Conflicting peer dependency: react#17.0.2

Im having trouble with production for my app to heroku.
the log im getting when trying to push from node git:
Counting objects: 100% (194/194), done.
Delta compression using up to 8 threads
Compressing objects: 100% (185/185), done.
Writing objects: 100% (194/194), 703.98 KiB | 4.96 MiB/s, done.
Total 194 (delta 70), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-22 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 18.x...
remote: Downloading and installing node 18.13.0...
remote: Using default npm version: 8.19.3
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: added 984 packages, and audited 985 packages in 38s
remote:
remote: 40 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 29 vulnerabilities (8 low, 18 moderate, 3 high)
remote:
remote: To address issues that do not require attention, run:
remote: npm audit fix
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > proshop#1.0.0 heroku-postbuild
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
remote:
remote: npm ERR! code ERESOLVE
remote: npm ERR! ERESOLVE could not resolve
remote: npm ERR!
remote: npm ERR! While resolving: react-paypal-button-v2#2.6.3
remote: npm ERR! Found: react#18.2.0
remote: npm ERR! node_modules/react
remote: npm ERR! react#"^18.2.0" from the root project
remote: npm ERR! peer react#"^16.8.0 || ^17.0.0-rc.1 || ^18.0.0" from #react-aria/ssr#3.4.1
remote: npm ERR! node_modules/#react-aria/ssr
remote: npm ERR! #react-aria/ssr#"^3.2.0" from #restart/ui#1.4.1
remote: npm ERR! node_modules/#restart/ui
remote: npm ERR! #restart/ui#"^1.4.1" from react-bootstrap#2.7.0
remote: npm ERR! node_modules/react-bootstrap
remote: npm ERR! react-bootstrap#"^2.7.0" from the root project
remote: npm ERR! 16 more (#restart/hooks, #restart/ui, #testing-library/react, ...)
remote: npm ERR!
remote: npm ERR! Could not resolve dependency:
remote: npm ERR! peer react#"^0.14.6 || 15.x.x || 16.x.x || 17.x.x" from react-paypal-button-v2#2.6.3
remote: npm ERR! node_modules/react-paypal-button-v2
remote: npm ERR! react-paypal-button-v2#"^2.6.3" from the root project
remote: npm ERR!
remote: npm ERR! Conflicting peer dependency: react#17.0.2
remote: npm ERR! node_modules/react
remote: npm ERR! peer react#"^0.14.6 || 15.x.x || 16.x.x || 17.x.x" from react-paypal-button-v2#2.6.3
remote: npm ERR! node_modules/react-paypal-button-v2
remote: npm ERR! react-paypal-button-v2#"^2.6.3" from the root project
remote: npm ERR!
remote: npm ERR! Fix the upstream dependency conflict, or retry
remote: npm ERR! this command with --force, or --legacy-peer-deps
remote: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
remote: npm ERR!
remote: npm ERR! See /tmp/npmcache.luihn/eresolve-report.txt for a full report.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.luihn/_logs/2023-01-10T23_16_50_967Z-debug-0.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: fc7ab23b834a092ca743dc214dafdda32868ba40
remote: !
remote: ! We have detected that you have triggered a build from source code with version
fc7ab23b834a092ca743dc214dafdda32868ba40
remote: ! at least twice. One common cause of this behavior is attempting to deploy code
from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to ikproshop.
remote:
To https://git.heroku.com/ikproshop.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ikproshop.git'
And my code is this file:
import React, { useEffect, useState } from 'react';
import { PayPalButton } from 'react-paypal-button-v2';
// import { PayPalScriptProvider, PayPalButtons } from '#paypal/react-paypal-js';
import axios from 'axios';
import { Link, useParams, useNavigate } from 'react-router-dom';
import { Button, Row, Col, ListGroup, Image, Card } from 'react-bootstrap';
import { useDispatch, useSelector } from 'react-redux';
import Message from '../components/Message';
import Loader from '../components/Loader';
import {
getOrderDetails,
payOrder,
deliverOrder,
} from '../actions/orderActions';
import {
ORDER_PAY_RESET,
ORDER_DELIVER_RESET,
} from '../constants/orderConstants';
const OrderScreen = () => {
const { id } = useParams();
const orderId = id;
const navigate = useNavigate();
const dispatch = useDispatch();
const [sdkReady, setSdkReady] = useState(false);
const orderDetails = useSelector((state) => state.orderDetails);
const { order, loading, error } = orderDetails;
const orderPay = useSelector((state) => state.orderPay);
const { loading: loadingPay, success: successPay } = orderPay;
const orderDeliver = useSelector((state) => state.orderDeliver);
const { loading: loadingDeliver, success: successDeliver } = orderDeliver;
const userLogin = useSelector((state) => state.userLogin);
const { userInfo } = userLogin;
if (!loading) {
// Calculate prices
const addDecimals = (num) => {
return (Math.round(num * 100) / 100).toFixed(2);
};
order.itemsPrice = addDecimals(
order.orderItems.reduce((acc, item) => acc + item.price * item.qty, 0)
);
}
useEffect(() => {
if (!userInfo) {
navigate('/login');
}
const addPayPalScript = async () => {
const { data: clientId } = await axios.get(`/api/config/paypal`);
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = `https://www.paypal.com/sdk/js?client-id=${clientId}`;
script.async = true;
script.onload = () => {
setSdkReady(true);
};
document.body.appendChild(script);
};
if (!order || successPay || successDeliver) {
dispatch({ type: ORDER_PAY_RESET });
dispatch({ type: ORDER_DELIVER_RESET });
dispatch(getOrderDetails(orderId));
} else if (!order.isPaid) {
if (!window.paypal) {
addPayPalScript();
} else {
setSdkReady(true);
}
}
}, [
dispatch,
orderId,
successPay,
successDeliver,
order,
navigate,
userInfo,
]);
const deliverHandler = () => {
dispatch(deliverOrder(order));
};
const successPaymentHandler = (paymentResult) => {
dispatch(payOrder(orderId, paymentResult));
};
return loading ? (
<Loader />
) : error ? (
<Message variant='danger'>{error}</Message>
) : (
<>
<h1>Order {order._id}</h1>
<Row>
<Col md={8}>
<ListGroup variant='flush'>
<ListGroup.Item>
<h2>Shipping</h2>
<p>
<strong>Name: </strong> {order.user.name}
</p>
<p>
<strong>Email: </strong>{' '}
<a href={`mailto:${order.user.email}`}>{order.user.email}</a>
</p>
<p>
<strong>Address:</strong>
{order.shippingAddress.address}, {order.shippingAddress.city},{' '}
{order.shippingAddress.postalCode},{' '}
{order.shippingAddress.country},
</p>
{order.isDelivered ? (
<Message variant='success'>
Delivered on {order.deliveredAt}
</Message>
) : (
<Message variant='danger'>Not Delivered</Message>
)}
</ListGroup.Item>
<ListGroup.Item>
<h2>Payment Method</h2>
<p>
<strong>Method: </strong>
{order.paymentMethod}
</p>
{order.isPaid ? (
<Message variant='success'>Paid on {order.paidAt}</Message>
) : (
<Message variant='danger'>Not Paid</Message>
)}
</ListGroup.Item>
<ListGroup.Item>
<h2>Order Items</h2>
{order.orderItems.length === 0 ? (
<Message>Order Is Eempty</Message>
) : (
<ListGroup variant='flush'>
{order.orderItems.map((item, index) => (
<ListGroup.Item key={index}>
<Row>
<Col md={1}>
<Image
src={item.image}
alt={item.name}
fluid
rounded
/>
</Col>
<Col>
<Link to={`/product/${item.product}`}>
{item.name}
</Link>
</Col>
<Col md={4}>
{item.qty} x ${item.price} = ${item.qty * item.price}
</Col>
</Row>
</ListGroup.Item>
))}
</ListGroup>
)}
</ListGroup.Item>
</ListGroup>
</Col>
<Col md={4}>
<Card>
<ListGroup variant='flush'>
<ListGroup.Item>
<h2>Order Summary</h2>
</ListGroup.Item>
<ListGroup.Item>
<Row>
<Col>Items</Col>
<Col>${order.itemsPrice}</Col>
</Row>
</ListGroup.Item>
<ListGroup.Item>
<Row>
<Col>Shipping</Col>
<Col>${order.shippingPrice}</Col>
</Row>
</ListGroup.Item>
<ListGroup.Item>
<Row>
<Col>Tax</Col>
<Col>${order.taxPrice}</Col>
</Row>
</ListGroup.Item>
<ListGroup.Item>
<Row>
<Col>Total</Col>
<Col>${order.totalPrice}</Col>
</Row>
</ListGroup.Item>
{!order.isPaid && (
<ListGroup.Item>
{loadingPay && <Loader />}
{!sdkReady ? (
<Loader />
) : (
<PayPalButton
amount={order.totalPrice}
onSuccess={successPaymentHandler}
></PayPalButton>
)}
</ListGroup.Item>
)}
{loadingDeliver && <Loader />}
{userInfo &&
userInfo.isAdmin &&
order.isPaid &&
!order.isDelivered && (
<ListGroup.Item>
<Button
type='button'
className='btn btn-block'
onClick={deliverHandler}
>
Mark as Delivered
</Button>
</ListGroup.Item>
)}
</ListGroup>
</Card>
</Col>
</Row>
</>
);
};
export default OrderScreen;
My package.json:
{
"name": "proshop",
"version": "1.0.0",
"description": "MERN shopping cart app",
"main": "server.js",
"type": "module",
"node": "18.6",
"scripts": {
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"data:import": "node backend/seeder",
"data:destroy": "node backend/seeder -d",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
},
"author": "Idan Kfir",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
"heroku": "^7.67.1",
"jsonwebtoken": "^9.0.0",
"mongoose": "^6.8.2",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"concurrently": "^7.6.0",
"nodemon": "^2.0.20"
}
}
Now the bug from what im seeing is with the react-paypal-button-v2 not working along with react version 18.2. (fix me if im wrong)
I tried to use another paypal buttons without changing the context too much but I failed over and over again. even tried with chatGPT to codeReview it and help me change to another framework but it meant changing the whole client id config and such. is there any easy fix for that with a framework which is easier and maybe contact with my code and my sdk that I implement already?
Thanks in advance hope I didn't say too much.
So I found the answer, I had to remove all the paypal checkouts from my dependencies at package.json at the frontend.
also deleted them from node_modules.
Writing this for anybody else who runs with issues with the react-paypal-buttons-v2.

Unable to push to Heroku due to 'Cannot find module '#babel/plugin-transform-runtime'

I have tried just about everything to try push my app to heroku. This is the latest error.
remote: Compiling...
remote: Compilation failed:
remote: Hash: f8c9f7bfa5b264fe0b58
remote: Version: webpack 4.46.0
remote: Time: 727ms
remote: Built at: 07/07/2022 3:14:08 AM
remote: 2 assets
remote: Entrypoint application = js/application-322f69d6aee6dcb0030d.js js/application-322f69d6aee6dcb0030d.js.map
remote: [0] ./app/javascript/packs/application.js 4.08 KiB {0} [built] [failed] [1 error]
remote:
remote: ERROR in ./app/javascript/packs/application.js
remote: Module build failed (from ./node_modules/babel-loader/lib/index.js):
remote: Error: Cannot find module '#babel/plugin-transform-runtime'
remote: Require stack:
remote: - /tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/files/plugins.js
remote: - /tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/files/index.js
remote: - /tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/index.js
remote: - /tmp/build_55951252/node_modules/babel-loader/lib/index.js
remote: - /tmp/build_55951252/node_modules/loader-runner/lib/loadLoader.js
remote: - /tmp/build_55951252/node_modules/loader-runner/lib/LoaderRunner.js
remote: - /tmp/build_55951252/node_modules/webpack/lib/NormalModule.js
remote: - /tmp/build_55951252/node_modules/webpack/lib/NormalModuleFactory.js
remote: - /tmp/build_55951252/node_modules/webpack/lib/Compiler.js
remote: - /tmp/build_55951252/node_modules/webpack/lib/webpack.js
remote: - /tmp/build_55951252/node_modules/webpack-cli/bin/utils/validate-options.js
remote: - /tmp/build_55951252/node_modules/webpack-cli/bin/utils/convert-argv.js
remote: - /tmp/build_55951252/node_modules/webpack-cli/bin/cli.js
remote: - /tmp/build_55951252/node_modules/webpack/bin/webpack.js
remote: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
remote: at resolve (/tmp/build_55951252/node_modules/v8-compile-cache/v8-compile-cache.js:164:23)
remote: at resolveStandardizedName (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/files/plugins.js:111:7)
remote: at resolvePlugin (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/files/plugins.js:55:10)
remote: at loadPlugin (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/files/plugins.js:63:20)
remote: at loadPlugin.next (<anonymous>)
remote: at createDescriptor (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-descriptors.js:187:16)
remote: at createDescriptor.next (<anonymous>)
remote: at step (/tmp/build_55951252/node_modules/gensync/index.js:261:32)
remote: at evaluateAsync (/tmp/build_55951252/node_modules/gensync/index.js:291:5)
remote: at /tmp/build_55951252/node_modules/gensync/index.js:44:11
remote: at Array.forEach (<anonymous>)
remote: at Function.async (/tmp/build_55951252/node_modules/gensync/index.js:43:15)
remote: at Function.all (/tmp/build_55951252/node_modules/gensync/index.js:216:13)
remote: at Generator.next (<anonymous>)
remote: at createDescriptors (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-descriptors.js:142:41)
remote: at createDescriptors.next (<anonymous>)
remote: at createPluginDescriptors (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-descriptors.js:138:17)
remote: at createPluginDescriptors.next (<anonymous>)
remote: at plugins (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-descriptors.js:65:26)
remote: at plugins.next (<anonymous>)
remote: at mergeChainOpts (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-chain.js:419:34)
remote: at mergeChainOpts.next (<anonymous>)
remote: at /tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-chain.js:378:14
remote: at Generator.next (<anonymous>)
remote: at loadFileChain (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-chain.js:232:24)
remote: at loadFileChain.next (<anonymous>)
remote: at buildRootChain (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/config-chain.js:95:27)
remote: at buildRootChain.next (<anonymous>)
remote: at loadPrivatePartialConfig (/tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/partial.js:103:62)
remote: at loadPrivatePartialConfig.next (<anonymous>)
remote: at /tmp/build_55951252/node_modules/babel-loader/node_modules/#babel/core/lib/config/partial.js:149:25
remote: at Generator.next (<anonymous>)
remote: at step (/tmp/build_55951252/node_modules/gensync/index.js:269:25)
remote: at evaluateAsync (/tmp/build_55951252/node_modules/gensync/index.js:291:5)
remote: at /tmp/build_55951252/node_modules/gensync/index.js:93:9
remote:
remote:
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
There is nothing in my /javascript/packs/application.js. I have not found anything that references this file as a necessary step to build the referenced module in the error.
This is my package.json
{
"name": "example-app",
"private": true,
"dependencies": {
"#babel/plugin-proposal-decorators": "^7.18.6",
"#babel/plugin-proposal-object-rest-spread": "^7.18.6",
"#babel/plugin-proposal-private-methods": "^7.18.6",
"#popperjs/core": "^2.0.0-alpha.1",
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"#rails/webpacker": "5.4.3",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-runtime": "^6.26.0",
"bootstrap": "5.0.0-beta2",
"node": "^18.4.0",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0"
},
"devDependencies": {
"#babel/core": "^7.18.6",
"#babel/plugin-proposal-class-properties": "^7.18.6",
"#babel/plugin-proposal-private-property-in-object": "^7.18.6",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-transform-destructuring": "^7.18.6",
"#babel/preset-env": "^7.18.6",
"babel-loader": "^8.2.5",
"webpack-config": "^7.5.0",
"webpack-dev-server": "^4.9.3"
},
"resolutions": {
"#babel/core": "7.15.0",
"#babel/preset-env": "7.15.0"
},
"postinstall": "npm rebuild node-sass"
}
Any help would be greatly appreciated.
The error means you need to install the package: #babel/plugin-transform-runtime.
It’s either a peer dependency for another Babel plugin, or your build is using it directly (naming can be different in Babel config).

Babel transpilation reserved keyword 'package' error on Heroku

I'm working on a MERN stack app with Babel on the server side of things so that I can write ES6. I'm getting an error when I try to deploy to Heroku: "Unexpected reserved word 'package'"
My Heroku-related scripts:
{
"build": "babel . -d build --ignore ./client,node_modules",
"heroku-postbuild": "YARN_PRODUCTION=false yarn build && yarn --cwd client install && yarn --cwd client build"
}
Full error message:
remote: SyntaxError: /tmp/build_92b72922d4bd2872f60dec7f1e038c5d/.heroku/node/lib/node_modules/npm/node_modules/init-package-json/default-input.js: Unexpected reserved word 'package' (48:11)
remote:
remote: 46 | }}
remote: 47 |
remote: > 48 | var name = package.name || basename
remote: | ^
remote: 49 | var spec
remote: 50 | try {
remote: 51 | spec = npa(name)
remote: at Object._raise (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:757:17)
remote: at Object.raiseWithData (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:750:17)
remote: at Object.raise (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:744:17)
remote: at Object.checkReservedWord (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:10916:14)
remote: at Object.parseIdentifierName (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:10876:12)
remote: at Object.parseIdentifier (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:10847:23)
remote: at Object.parseExprAtom (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:9958:27)
remote: at Object.parseExprAtom (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:4648:20)
remote: at Object.parseExprSubscripts (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:9688:23)
remote: at Object.parseMaybeUnary (/tmp/build_92b72922d4bd2872f60dec7f1e038c5d/node_modules/#babel/parser/lib/index.js:9668:21) {
remote: loc: Position { line: 48, column: 11 },
remote: pos: 1484,
remote: code: 'BABEL_PARSE_ERROR'
remote: }
Couple of things to note:
I had to add node_modules to Babel ignore (I'm not sure whether this is a good idea though) because it was giving me an Unexpected token error:
import * as $protobuf from $DEPENDENCY;` // On the `$` of "$DEPENDENCY"
I assumed I didn't want to transpile the client folder because React has its own build script (default one)
My babel config:
module.exports = {
presets: ["#babel/preset-env", "#babel/preset-react"],
plugins: ["#babel/plugin-proposal-class-properties"]
};
My folder structure:
Found a fix:
I just had to put every server related files/folder into its own directory and update the babel transpilation script as needed

BABEL_PARSE_ERROR when deploying Nodejs app on heroku

I am deploying node js application on heroku server. I am using webpack for es6 syntax and its working fine everything on my local.
But when I am trying to deploy code on heroku it gives BABEL_PARSE_ERROR.
remote: > taleem-backend#1.0.0 build /tmp/build_dbe1f098c9b56734350ccb6e4f4c0166
remote: > rimraf dist/ && babel ./ --out-dir dist
remote:
remote: SyntaxError: /tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/.heroku/node/lib/node_modules/npm/docs/gatsby-browser.js: Unexpected token (7:9)
remote:
remote: 5 |
remote: 6 | export const wrapPageElement = ({ element, props }) => {
remote: > 7 | return <Layout {...props} >{element}</Layout>
remote: | ^
remote: 8 | }
remote: 9 |
remote: at Parser.raise (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:7017:17)
remote: at Parser.unexpected (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:8395:16)
remote: at Parser.parseExprAtom (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9673:20)
remote: at Parser.parseExprSubscripts (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9259:23)
remote: at Parser.parseMaybeUnary (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9239:21)
remote: at Parser.parseExprOps (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9109:23)
remote: at Parser.parseMaybeConditional (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9082:23)
remote: at Parser.parseMaybeAssign (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:9037:21)
remote: at Parser.parseExpression (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:8989:23)
remote: at Parser.parseReturnStatement (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/#babel/parser/lib/index.js:11057:28) {
remote: pos: 209,
remote: loc: Position { line: 7, column: 9 },
remote: code: 'BABEL_PARSE_ERROR'
remote: }
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! taleem-backend#1.0.0 build: `rimraf dist/ && babel ./ --out-dir dist`
remote: npm ERR! Exit status 1
Above error is coming in node_modules, but I am already ignoring my node_modules in webpack.config.js and I double check its working fine in my local (ignore logic)
heroku local web
I run above command as its mentioned in heroku docs and
its also working fine
https://devcenter.heroku.com/articles/deploying-nodejs
But when I run
git push heroku master
I got above error. Kindly help me on this to fix this issue.
Thanks
EDIT
webpack.config.js
module.exports = (api) => {
api.cache(true)
return {
ignore: [
"babel.config.js",
"dist",
"package.json",
"node_modules",
'.babelrc'
]
}
}
package.json
"scripts": {
"start": "npm run build && node dist/bin/www",
"build": "rimraf dist/ && babel ./ --out-dir dist",
"watch:dev": "nodemon"
},
Now I fixed that by updating app structure
"build": "rimraf dist/ && babel app/ --out-dir dist",

Heroku Push rejected: fails when building dependencies if Grunt is one of them - "(node) warning: Recursive process.nextTick detected..."

I'm quite puzzled since I pushed to Heroku with no problem twice today before it started rejecting any git push attempt. (I added comments to the log below.)
//Everything is smooth and then...
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
//hundreds of that line above again and again...
// Then this line below ONCE
remote: npm(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
//Then hundreds of that other line again...
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
remote: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
//And eventually...
remote:
remote: util.js:35
remote: var str = String(f).replace(formatRegExp, function(x) {
remote: ^
remote: RangeError: Maximum call stack size exceeded
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to nameOfProject.
remote:
To https://git.heroku.com/nameOfProject.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/nameOfProject.git'
Locally, I can npm rebuild with no problem and run the app too.
None of my util.js file has var str = String(f).replace(formatRegExp, funct... anywhere, in fact, I can't find that line of code.
From what I read in other questions, the "(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral." could be related to Grunt, but I didn't touch my Gruntfile.js for days if not weeks so I doubt that would be the issue.
EDIT
Turns out that Grunt IS causing the problem. If we take every Grunt related dependency out of our package.json file, we can push to Heroku.
So my guess is that Grunt updated something, that thing is out of our control and it somehow doesn't work wit Heroku.
For now, our solution is to not push Grunt to heroku since we don't need it there anyway. But it would be great to understand what's going on. If you experience the same issue or have a better understanding please share!
Here is our package.json:
{
"name": "ourName",
"version": "0.0.1",
"dependencies": {
"#google/maps": "^0.3.1",
"angular-i18n": "1.6.6",
"angular-touch": "1.6.6",
"async": "0.2.8",
"bluebird": "^3.5.1",
"bwip": "~0.6.3",
"cloudinary": "1.0.1",
"connect-flash": "0.1.0",
"connect-mongodb": "1.1.4",
"cookie": "^0.3.1",
"cron": "1.0.1",
"ejs": "0.8.4",
"express": "3.2.5",
"express-subdomain": "1.0.5",
"feed-read": "0.0.1",
"file-system": "^2.2.2",
"google-auth-library": "^0.10.0",
"googleapis": "^17.1.0",
"http-auth": "1.2.2",
"ipware": "^1.0.0",
"jade": "~0.27.4",
"js2xml": "0.0.6",
"jsonify": "0.0.0",
"lame": "1.2.1",
"mailchecker": "3.0.27",
"mailchimp": "*",
"mailchimp-api-v3": "1.7.0",
"moment": "2.1.0",
"mongodb": "1.3.10",
"mongoose": "3.6.13",
"netmask": "^1.0.6",
"newrelic": "~1.3.1",
"node-schedule": "1.2.3",
"nodemailer": "2.4.2",
"nodetime": ">=0.8.4",
"object-assign": "^4.1.1",
"octobat-npm": "^2.0.1",
"optimist": "0.3.4",
"password-generator": "2.1.0",
"pdfkit": "~0.2.7",
"request": "2.81.0",
"rollbar": "2.0.0",
"stripe": "4.24.0",
"temp": "~0.6.0",
"time": "0.8.0",
"timekit": "*",
"touch": "^3.1.0",
"twilio": "^2.11.1",
"uglify-js": "1.3.3",
"underscore": "^1.8.3",
"v8tools": "*",
"wav": "0.1.2",
"when": "1.7.1",
"xml2js": "0.4.17"
},
"devDependencies": {
"angular-momentjs": "^0.2.2",
"autoprefixer": "^7.1.2",
"chai": "*",
"cssnano": "^3.10.0",
"database-cleaner": "0.7.0",
"expect.js": "*",
"factory-lady": "0.1.0",
"grunt": ">=0.4.1", //REMOVED AND THEN IT WORKS
"grunt-contrib-concat": "^1.0.1", //REMOVED AND THEN IT WORKS
"grunt-contrib-imagemin": "^1.0.1", //REMOVED AND THEN IT WORKS
"grunt-contrib-jshint": "^1.1.0", //REMOVED AND THEN IT WORKS
"grunt-contrib-uglify": "^3.0.1", //REMOVED AND THEN IT WORKS
"grunt-hash": "^0.5.0", //REMOVED AND THEN IT WORKS
"grunt-postcss": "^0.8.0", //REMOVED AND THEN IT WORKS
"lodash": "1.2.x",
"mocha": "1.10.0",
"moment": "^2.1.0",
"pixrem": "^3.0.2",
"vows": ">=0.6.4",
"zombie": "2.0.x"
},
"engines": {
"node": "0.10.x",
"npm": "3.9.2"
},
"scripts": {
"test": "NODE_ENV=test vows test/api/*.js test/web/*.js --spec",
"start": ""
}
}
I see your problem might be coming from this very lines I comment at the ending of your package.json
"engines": {
"node": "0.10.x", //here
"npm": "3.9.2"
},
"scripts": {
"test": "NODE_ENV=test vows test/api/*.js test/web/*.js --spec",
"start": "" //here
}
}
On the engines your version of node can result to that error, so I suggest you change your engines to this below:
"engines": {
"node": "*", //this should make your app run on the most recent version of node
"npm": "*" //this should make your app run on the most recent version of npm
Then is your scripts, you still didn't specify your entry point from your start. Your scripts should be something like this:
"scripts": {
"test": "NODE_ENV=test vows test/api/*.js test/web/*.js --spec",
"start": "node index.js" //this is where you should place your entry point.
}
Note: It is not a most to use index.js, you can write your entry point to the app with the name you called it, maybe app.js or server.js or whatever your called it.
And I also notice you didn't have a "main": "" in your package.json.
Implement these corrections to your package.json and your problem should be fixed

Resources