Failing to run an old repo on localhost - reactjs

I'm trying to get the repo of a web page running on localhost, to later try to update some of the outdated dependencies. This web page runs on Next JS with Strapi version 3. After Strapi version 4 went live, the team had trouble updating the content on the page. I wanted to try and see how I could help, but have trouble even running the website locally. I'm a beginner and would be happy to learn about any suggestions.
Here is the folder structure:
backend
api: config, controllers, models, services folders for Strapi
components: layout, links, meta, sections folders for Vue JS
config: database.js, server.js
extensions: Includes JSON Web Token integration
public: uploads folder with icons and images used on the website
Also the following files:
.editorconfig
.eslintrc
.strapi-updater.json
package.json
yarn.lock
frontend
components: elements and sections folders with React JS
packages: eslint-config-ibmdotcom & stylelint-config-ibmdotcom
pages: _app.js, _document.js and [[...slug]].js to implement Next JS' optional catch all routes feature
patches: carbon ibmdotcom, carbon type and patch package patches
public: A few icons to be used on the website
styles: Includes global.scss
utils: api.js, media.js and types.js
Also the following files:
.eslintrc
.lintstagedrc
.stylelintrc
jsconfig.json
package.json
yarn.lock
node_modules
patches
Also the following files:
.yarnclean
package-lock.json
package.json
yarn.lock
Here are the dependencies:
In frontend/package.json:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --port 3200",
"build": "next build",
"start": "next start --port 3400",
"postinstall": "patch-package",
"debug": "NODE_OPTIONS='--inspect' next --port 3300"
},
"dependencies": {
"#carbon/ibmdotcom-react": "^1.14.0",
"#carbon/ibmdotcom-styles": "^1.14.0",
"#carbon/icons-react": "^10.22.0",
"#carbon/pictograms-react": "^11.0.0",
"carbon-components-react": "^7.26.0",
"formik": "^2.2.6",
"next": "10.0.5",
"next-seo": "^4.17.0",
"patch-package": "^6.2.2",
"postinstall-postinstall": "^2.1.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-hook-form": "^6.14.2",
"sass": "^1.32.2",
"yup": "^0.32.8"
},
"devDependencies": {
"eslint": "^7.17.0"
}
}
In backend/package.json:
{
"name": "backend",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"knex": "<0.20.0",
"pg": "^8.5.1",
"sqlite3": "latest",
"strapi": "3.4.3",
"strapi-admin": "3.4.3",
"strapi-connector-bookshelf": "3.4.3",
"strapi-plugin-content-manager": "3.4.3",
"strapi-plugin-content-type-builder": "3.4.3",
"strapi-plugin-email": "3.4.3",
"strapi-plugin-img": "^1.0.1",
"strapi-plugin-upload": "3.4.3",
"strapi-plugin-users-permissions": "3.4.3",
"strapi-utils": "3.4.3"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "c78c2abc-df48-4be1-8dcf-1266d358a02b"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
Here is what I tried so far:
Ran npm install
Got the following error:
> website#1.0.0 postinstall
> patch-package
sh: patch-package: command not found
npm ERR! code 127
npm ERR! path /Users/sgt/Documents/Stroma/website
npm ERR! command failed
npm ERR! command sh -c patch-package
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/sgt/.npm/_logs/2022-09-02T09_46_38_695Z-debug-0.log
Ran npm i patch-package
Got the following error:
added 50 packages, and audited 68 packages in 5s
6 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
sgt#mb-sgt website % npm install
> website#1.0.0 postinstall
> patch-package
patch-package 6.4.7
Applying patches...
**ERROR** Failed to apply patch for package patch-package at path
node_modules/patch-package
This error was caused because patch-package has changed since you
made the patch file for it. This introduced conflicts with your patch,
just like a merge conflict in Git when separate incompatible changes are
made to the same piece of code.
Maybe this means your patch file is no longer necessary, in which case
hooray! Just delete it!
Otherwise, you need to generate a new patch file.
To generate a new one, just repeat the steps you made to generate the first
one.
i.e. manually make the appropriate file changes, then run
patch-package patch-package
Info:
Patch file: patches/patch-package+6.2.2.patch
Patch was made for version: 6.2.2
Installed version: 6.4.7
---
patch-package finished with 1 error(s).
up to date, audited 68 packages in 1s
6 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Ran npx patch-package patch-package --exclude 'nothing'
Got the following error:
patch-package 6.4.7
patch-package: you have both yarn.lock and package-lock.json
Defaulting to using npm
You can override this setting by passing --use-yarn or deleting
package-lock.json if you don't need it
• Creating temporary folder
• Installing patch-package#6.4.7 with npm
• Diffing your files with clean files
⁉️ Not creating patch file for package 'patch-package'
⁉️ There don't appear to be any changes.
What is the problem here? Does my method seem correct?
Happy to provide more information. Thanks for reading!

Related

Npm script for building react app working locally but not in pipeline

I have the following package.json for my React project
{
"name": "webforms-react-sample",
"version": "1.0.0",
"description": "Sample projects for hosting React apps in a WebForms application.",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --config webpack.dev.js",
"build-dev": "npx webpack --config webpack.dev.js",
"build-prod": "npx webpack --config webpack.prod.js"
},
"author": "Dimitris Vardalis",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.1.0",
"#babel/core": "^7.1.0",
"#babel/preset-env": "^7.1.0",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^6.7.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"style-loader": "^0.23.0",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"react-hot-loader": "^4.6.5",
"react-router-dom": "^5.2.0"
}
}
I'm trying to run the build-dev script. When trying locally I can make that script to work as is expected so build is made. But when going to the build pipeline is returning me this:
npm WARN exec The following package was not found and will be installed: webpack#5.75.0
CLI for webpack must be installed.
> webforms-react-sample#1.0.0 build-dev
webpack-cli (https://github.com/webpack/webpack-cli)
We will use "npm" to install the CLI via "npm install -D webpack-cli".
> npx webpack --config webpack.dev.js
Do you want to install 'webpack-cli' (yes/no):
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
I'm using Azure Devops and a windows machine agent (always using the latest version) for running the pipeline. And yes I'm installing npm packages before the step when trying to run that script. I don't have any npm cache step to avoid Azure caching old files and not updating on releases (this happened to me on other pipelines).
Current pipeline is this (see pictures)
pipeline steps part 1
Pipeline steps part2
I have already tried uninstalling the packages and reinstalling them, same results and been breaking my head for a while and still the same results.
Well I made it work by changing npm install step on React to npm install --force.

No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"

Im trying to deploy a Next app using vercel cli. I have run vercel build and that was completed successfully with no errors - context provided below. I have run the vercel deploy --prebuilt command and it was deployed with no errors. When I try to move the project from the preview enviroment to the production environment I error
Error: No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"
this is my package.json
{
"name": "portfolio-website",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"#heroicons/react": "^2.0.12",
"#next/swc-darwin-x64": "^12.3.2",
"framer-motion": "^7.6.2",
"next": "^12.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.38.0",
"react-simple-typewriter": "^4.0.5",
"react-social-icons": "^5.15.0"
},
"devDependencies": {
"#types/node": "18.11.7",
"#types/react": "18.0.24",
"#types/react-dom": "18.0.8",
"autoprefixer": "^10.4.12",
"eslint": "8.26.0",
"eslint-config-next": "13.0.0",
"postcss": "^8.4.18",
"tailwind-scrollbar": "^2.0.1",
"tailwindcss": "^3.2.1",
"typescript": "4.8.4"
},
"optionalDependencies": {
"#next/swc-linux-x64-gnu": "12.3.2"
}
}
I also had the error - for the context
warn - Attempted to load #next/swc-darwin-x64, but it was not installed
error - Failed to load SWC binary for darwin/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc
info - Creating an optimized production build .Error: Command "npm run build" exited with
I had to delete my package.lock.json fill and node_modules and run npm i #next/swc-darwin-x64 and npm i even tho the dependency at the time was already in my lock file.
I have also tried downgrading my next version but to no avail.
Have tried deploying directly from my git repository but i aslo get the same error
[22:29:17.748] Cloning github.com/xxxxx/xxxxxx (Branch: main, Commit: 0fb5a5a)
[22:29:18.540] Cloning completed: 791.508ms
[22:29:19.131] Looking up build cache...
[22:29:19.371] Build Cache not found
[22:29:19.420] Running "vercel build"
[22:29:20.057] Vercel CLI 28.4.12-05a80a4
[22:29:20.485] Installing dependencies...
[22:29:21.273] npm ERR! code EBADPLATFORM
[22:29:21.275] npm ERR! notsup Unsupported platform for #next/swc-darwin-x64#12.3.2: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","arch":"x64"})
[22:29:21.276] npm ERR! notsup Valid OS: darwin
[22:29:21.276] npm ERR! notsup Valid Arch: x64
[22:29:21.276] npm ERR! notsup Actual OS: linux
[22:29:21.276] npm ERR! notsup Actual Arch: x64
[22:29:21.279]
[22:29:21.279] npm ERR! A complete log of this run can be found in:
[22:29:21.279] npm ERR! /vercel/.npm/_logs/2022-11-02T21_29_20_898Z-debug-0.log
[22:29:21.290] Warning: Could not identify Next.js version, ensure it is defined as a project dependency.
[22:29:21.364] Error: No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"
I have been getting this error on vercel deployments although I have a next in the dependencies. What I find has been letting me get a good deployment is clearing the cache via
git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master
When this does not work for me I delete the yarn.lock file and get a good build, maybe a conflict between npm and yarn

How to install next-js with react 17?

How I can install next.js with React 17? When I type:
npx create-next-app --ts, npx installed Next with React 18, but I can't use React 18, because Stripe not working at the moment with R18 (https://www.npmjs.com/package/stripe).
You'd need to use an older version of Next JS.
The latest one I can see with React 17 is 12.1.2, so you can start your project with the following:
npx create-next-app#12.1.2
You can check the release change logs for Next JS here:
https://github.com/vercel/next.js/releases
If you've already created the project:
remove new versions:
npm uninstall next react react-dom #types/react #types/react-dom
install old versions:
npm install next#12.1.2 react#17.0.2 react-dom#17.0.2
npm install -D #types/react#17.0.2 #types/react-dom#17.0.2
I found an alternative approach , first create a new nextjs typescript project using npx create-next-app#latest --ts
. And then copied the versions of all the dependencies and devDependencies to package.json . after replacing the version delete node_modules folder and package-lock.json file . after that run this command npm install .
Here is a sample package.json. I got this after create new nextjs project.
{
"name": "demo",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.2.4",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"#types/node": "18.7.1",
"#types/react": "18.0.17",
"#types/react-dom": "18.0.6",
"eslint": "8.21.0",
"eslint-config-next": "12.2.4",
"typescript": "4.7.4"
}
}

Problem with NPX create-react-app. Keeps getting stuck at "Found 0 Vulnerabilties"

So I am trying to create a new React project using npx create-react-project but it keeps getting stuck after downloading the packages. So far the folder only contains the node modules and the 2 package.json files. The create-react-app goes well until it reaches found 0 vulnerabilities. I have done this in different folders and different hard drives but the same result. It just doesn't go further.
I also deleted my previous global create-react-app installation but this didn't make a difference either.
NPM Version: 6.14.4
Node Version: v12.16.2
My package.json file only contains the following:
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"cra-template": "1.0.3",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-scripts": "3.4.1"
}
}
**SOLUTION FOR ME: ** I Disabled my Anti-Virus and it worked.
try:
sudo npm install npm#latest -g
and then create a new app.
Also, you need to install git before run npx:
sudo apt install git

Removing Babel from project? (React, Parceljs)

I'm struggling with correctly configuring Babel in my React and Parceljs project. Right now, all I'm trying to do is completely remove babel from my project to start again with a clean slate. I've gone ahead and 'npm remove'-ed babel, as well as deleted my node.modules and package.lock.json.
This is my package.json currently.
"scripts": {
"dev": "parcel public/index.html",
"start": "parcel public/index.html",
"prod": "parcel build public/index.html"
},
"author": "Me",
"license": "ISC",
"dependencies": {
"parcel-bundler": "^1.12.3",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
However when running 'npm install' again, the babel files reappear and in my package.lock.json and node_modules.
And I'm still getting these errors that only appeared once I started install #babel packages.
Error: Cannot find module '#babel/core'
...
× Cannot read property 'length' of undefined
...
Parcel has been keeping a cache directory. Removing that and rebuilding fixed the problem.

Resources