create-react-app dependency version issues with React 18 - npm

npx create-react-app my-project results in the following dependency errors:
npx version: 8.5.0
Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: react-18#0.1.0
npm ERR! Found: react#18.0.0
npm ERR! node_modules/react
npm ERR! react#"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"<18.0.0" from #testing-library/react#12.1.5
npm ERR! node_modules/#testing-library/react
npm ERR! #testing-library/react#"^12.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
The command still produces a project directory, but running npm start in the created directory errors with web-vitals missing from node-modules.
Solutions tried
Running the same command with --force or --legacy-peer-deps as suggested by the above error message doesn't solve the problem.
Deleting node_modules and package-lock.json and running npm i also doesn't solve the problem.
Update
The problem has been fixed with the latest update of create-react-app. Now it creates a project without any problem.

Until this is fixed for now you can delete the node_modules folder and package-lock.json. Next, open package.json and change
"react": "^18.0.0" & "react-dom": "^18.0.0" to an earlier version e.g:
"react": "^17.0.2" & "react-dom": "^17.0.2".
Finally, you can run npm install.
Alternative Solution (Try this first!):
solution suggested by joooni1998):
delete both node_modules and package-lock.json
run npm i web-vitals --save-dev
run npm install
and then you can use npm run build and npm start again

Check here for the Github issue.
Here is a temporary workaround:
Install cra-template to a separate folder (other than your new
project app's folder) using "npm install cra-template"
Go to the installed cra-template package folder and in file "template.json" change the line '"#testing-library/react": "^12.0.0"' to '"#testing-library/react": "^13.0.0"'
Go back to your root folder and run npx create-react-app my-app (your app name) --template file:PATH_TO_YOUR_CUSTOM_TEMPLATE
Additionally, you can let the build fail, remove the node_modules folder as well as the package-json.lock file. Open the package.json file and change the react and react-dom to an earlier version.
For example:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"cra-template": "1.1.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0"
},
"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"
]
}
}
Delete reportWebVitals.js
Remove import reportWebVitals from './reportWebVitals'; from index.js
Remove reportWebVitals(); from the bottom of index.js
Finally run npm install

It worked for me by deleting both 'node_modules' folder and 'package-lock.json' file. Then, I changed both react and react-dom version to 17.0.2 instead of 18.0.0 inside the package.json file as suggested by Gavriel's answer https://stackoverflow.com/a/71836018/12490294. Then, inside the app folder, I ran
npm i web-vitals --save-dev
Then
npm start
The app started successfully

Or you can try this npx --legacy-peer-deps create-react-app my-appname or goto index.js and remove the usage of web vitals
or downgrade npm with npm install -g npm#8.3.0 and create react app.

You could use yarn add create-react-app your-app instead

Try running either with --force or with --legacy-peer-deps, both will install dependencies without problems.
If that doesn't work, then delete the node modules folder and start installing from scratch

Related

How to get npm to install a single package?

I have downloaded an npm project, and npm install fails with a bunch of dependency errors. In an attempt to find the problem, I've tried installing each dependency individually with, e.g., npm install react, but the command ignores the single argument and instead gives the same errors as trying to install the entire project. In desperation I tried the example from https://docs.npmjs.com/cli/v8/commands/npm-install: 'npm install sax`, where sax has nothing to do with the project, and it still fails.
package.json is:
{
"name": "graphiql-explorer-example",
"homepage": "https://onegraph.github.io/graphiql-explorer-example",
"version": "0.1.0",
"private": true,
"dependencies": {
"graphiql": "^0.12.0",
"graphql": "^14.1.1",
"graphiql-explorer": "^0.6.2",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"flow": "flow",
"deploy": "gh-pages -d build",
"predeploy": "yarn build",
"prettier": "prettier --write \"src/**/*.js\" \"docs/**/*.md\" README.md"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"flow-bin": "^0.91.0",
"gh-pages": "^2.0.1"
},
"description": "Example usage of [OneGraph](https://www.onegraph.com)'s open source [GraphiQL explorer](https://github.com/OneGraph/graphiql-explorer).",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/OneGraph/graphiql-explorer-example.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/OneGraph/graphiql-explorer-example/issues"
}
}
The error messages are:
> npm install react
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: graphiql-explorer-example#0.1.0
npm ERR! Found: graphql#14.1.1
npm ERR! node_modules/graphql
npm ERR! graphql#"^14.1.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql#"^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0" from graphiql#0.12.0
npm ERR! node_modules/graphiql
npm ERR! graphiql#"^0.12.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
The log file (excluding a pile of "timing" and "silly" messages) is:
1 info using npm#8.8.0
2 info using node#v16.14.2
22 verbose title npm install sax
23 verbose argv "install" "sax"
41 http fetch GET 200 https://registry.npmjs.org/graphiql 144ms (cache revalidated)
43 http fetch GET 200 https://registry.npmjs.org/graphql 47ms (cache revalidated)
47 verbose stack Error: unable to resolve dependency tree
As you can see, npm parses the "sax" argument correctly on line 23, but then ignores it and tries to install graphiql instead.
How can I get npm to install a single package, such as the latest version of react, instead of trying to install all of the dependencies for graphiql-explorer?
the problem here is the peer dependencies of "sax"
there are some ways to avoid checking peer dependency.
Method 1
npm install <package name> --force
or
npm install <package name> --legacy-peer-deps
but it is not recommended,
Adding --legacy-peer-deps to your npm installation will bypass peerDependency auto-installation, but this may result in conflicts due to potentially breaking changes
try to resove conflicts manually, by getting the peer dependency details using
npm info name-of-module peerDependencies
for more information refer: What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?
There is a fix for running the npm install command.
$ npm install
According to your error message when running the installation command:
npm ERR! ERESOLVE unable to resolve dependency tree
It states that some dependencies are incompatible with others. To fix this, you need to run the installation command with the following flag.
$ npm install --legacy-peer-deps
This should resolve the issue of the dependencies being incompatible with each other.
In conclusion, the issue was that the dependencies were incompatible with each other. However, there is a fix!
$ npm install --legacy-peer-deps

PostCSS 8 Error When Installing Tailwind CSS in Vue 3 (v3.2.10) without Vite (PostCSS 8 is supported)

I'm using Vue version 3.2.10 without Vite and trying to install Tailwind CSS version 2.2.14 (latest).
IMPORTANT: Vue version 3.0.6 began supporting PostCSS 8 (see 3rd point in the GitHub documentation for the update, under "features")
After carefully following installation instructions, then running npm run serve I keep getting this error:
error in ./src/assets/main.css
Syntax Error: Error: PostCSS plugin tailwindcss requires PostCSS 8.
Migration guide for end-users:
https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users
Here is my package.json file:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.36",
"#fortawesome/free-brands-svg-icons": "^5.15.4",
"#fortawesome/free-regular-svg-icons": "^5.15.4",
"#fortawesome/free-solid-svg-icons": "^5.15.4",
"#fortawesome/vue-fontawesome": "^3.0.0-4",
"#headlessui/vue": "^1.4.1",
"core-js": "^3.6.5",
"date-fns": "^2.23.0",
"firebase": "^8.9.0",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-router": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0",
"autoprefixer": "^10.3.4",
"postcss": "^8.3.6",
"postcss-cli": "^8.3.1",
"tailwindcss": "^2.2.14"
}
As noted above, Vue 3.0.6 and beyond definitely support PostCSS 8. Also, the Tailwind CSS instructions for "PostCSS 7 compatibility build" do NOT work.
After following those instructions, I get this error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: postcss#7.0.36
npm ERR! node_modules/postcss
npm ERR! dev postcss#"^7" from the root project
npm ERR! postcss#"^7.0.32" from autoprefixer#9.8.6
npm ERR! node_modules/autoprefixer
npm ERR! dev autoprefixer#"^9" from the root project
npm ERR! autoprefixer#"^9.8.6" from #vue/cli-service#4.5.13
npm ERR! node_modules/#vue/cli-service
npm ERR! peer #vue/cli-service#"^3.0.0 || ^4.0.0-0" from #vue/cli-plugin-babel#4.5.13
npm ERR! node_modules/#vue/cli-plugin-babel
npm ERR! dev #vue/cli-plugin-babel#"~4.5.0" from the root project
npm ERR! 3 more (#vue/cli-plugin-router, #vue/cli-plugin-vuex, the root project)
npm ERR! 1 more (tailwindcss)
npm ERR! 42 more (#intervolga/optimize-cssnano-plugin, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer postcss#"^8.0.0" from postcss-cli#8.3.1
npm ERR! node_modules/postcss-cli
npm ERR! dev postcss-cli#"^8.3.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/mgav/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mgav/.npm/_logs/2021-09-08T21_09_08_052Z-debug.log
Thanks for your help!
It seems the problem (in some cases, anyway) is not directly linked to VueJS, but vue-cli instead.
The solution that worked for me is:
Update #vue/cli to "^5.0.0-beta.3" (was on "~4.5.0") - (link to that on npm)
Updated #vue/compiler to latest stable - (link to that - 3.2.11 right now - on npm)
Even though I wasn't using the postcss7-compat version, I followed the post's instructions to uninstall via npm uninstall tailwindcss #tailwindcss/postcss7-compat
Reinstalled latest versions of TailwindCSS, PostCSS and AutoPrefixer via npm install tailwindcss#latest postcss#latest autoprefixer#latest
That's it!
Note: This is not my work. I was directed by Lindsay Wardell (#lindsaykwardell) to a post on this Vuejs forum with the solution by Thomas Castelly (also no StackOverflow handle).
There is no issue with the latest stable packages of vue-cli (v4.5.13 right now).
It look like that your issue is more about managing the dependencies (you should give a read on node.dev about this topic) as basically, to use TailwindCSS with the latest Vue3 stable version only require to install the latest version of the dependencies with few command lines and it work without the box.
As example, you will find below the instructions to create a minimal Vue3/Tailwind project which works as is:
$ vue create vue3-tailwindcss
$ cd vue3-tailwindcss
$ npm install -D #vue/compiler-sfc tailwindcss#latest postcss#latest autoprefixer#latest
$ npm run serve
Version of node and Vue :
$ node --version
v16.5.0
$ vue --version
#vue/cli 4.5.13
About your issue, you could have used the following method to get it working with with latest stables packages :
In package.json make theses changes :
"#vue/cli-service": "~4.5.0" => "#vue/cli-service": "^4.5.13"
"vue": "^3.0.0" => "vue": "^3.2.11"
"#vue/compiler-sfc": "^3.0.0" => "#vue/compiler-sfc": "^3.2.11"
Then remove the file package-lock.json and run npm install.
Easy solution without Vite.
You can start a new project using a newer version of Vue CLI. Just reinstall it like:
npm uninstall -g #vue/cli
npm install -g #vue/cli#next
And create a new Vue 3 project. It will support PostCSS 8 without any problem.
Then follow the Tailwind 3 installation guide using PostCSS. Don't forget to include your *.vue files in tailwind.config.js.
And you are ready to go.
Look at this repo I built as a guide.
If you are having that same issue, uninstall tailwind CSS postcss and autoprefixer. See the command below:
npm uninstall tailwindcss postcss autoprefixer
Then install it with the command below :
npm install -D tailwindcss#latest postcss#latest autoprefixer#latest

Laravel 7 on homestead with npm error "cross-env"

[Update]
Vue complier 2.6.12 triggers this error when I try in npm clean-install
tarball tarball data for vue-template-compiler#2.6.12 (sha512-KIq15bxxxxxx) seems to be
corrupted. Trying one more time.
I run npm cache clean --force then change both versions to 2.6.11 but Vue changes its version automatically to 2.6.12 and can't get it working
I have been trying to install VueJs to a current Laravel 7 project. I reach this command
npm install && npm run dev
I got a warning of mismatch between Vue and the template compiler so I changed the package.json to make them both the same version
"vue": "^2.6.12",
"vue-template-compiler": "^2.6.12"
And changed their version in package-lock.json too.
then I deleted node_modules folder then run npm install again. I got multiple errors so I kept running the same command multiple times till it finished installing. Now I'm trying to run npm run dev but I get this error
errno ENOENT
npm ERR! # development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js
--progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! spawn ENOENT
How to fix it and make the application work with VueJs?
Have you tried prefixing cross-env calls in package.json with npx cross-env?
For example,
// OLD
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
// NEW
"development": "npx cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

Electron app won't run. cant figure out why

when typing npm start it gives me this error:
npm ERR! errno 1
npm ERR! helloworld#1.0.0 start: `electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the helloworld#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
here is the package.json
{
"name": "helloworld",
"version": "1.0.0",
"description": "my app",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "kamalyaka",
"license": "MIT"
}
Please help.
You need to first install all the dependencies.
Try executing
npm install
first in your project directory.
After the dependencies are installed then you can execute
npm start
which will start your electron app.

'webpack-dev-server' is not recognized as an internal or external command,

I cloned this Webpack Starter package through github using gitbash following a tutorial on pluralsight. I am trying to access webpack through Visual Studio Code's integrated terminal but i get the following error. I am new to this so kindly help me on this.
I am running a command
Raza Zaidi#RazaZaidi-PC MINGW64 ~/webpack-starter (master)
$ npm run dev
and then following error occurs
> yet-another-webpack-es6-starterkit#1.0.0 dev C:\Users\Raza Zaidi\webpack-starter
> webpack-dev-server --open --config webpack/webpack.config.dev.js
'webpack-dev-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yet-another-webpack-es6-starterkit#1.0.0 dev: `webpack-dev-server --open --config webpack/webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yet-another-webpack-es6-starterkit#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Raza Zaidi\AppData\Roaming\npm-cache\_logs\2018-08-14T20_16_29_017Z-debug.log
Webpack command should be present in location: node_modules\.bin\
In this case in package.json file we are referring to webpack-dev-server, but locally webpack-dev-server doesn't exist.
First run following command for global installation:
npm install -g webpack-dev-server
Second execute local installation command, which will create node_modules\.bin\webpack-dev-server:
npm install webpack-dev-server --save-dev
running
npm install -g webpack-dev-server
in cmd as an administrator solved my problem. I hope it helps others.
For me, instead of installing webpack-dev-server globally, I simply uninstalled and reinstalled the local package:
npm uninstall webpack-dev-server
npm install webpack-dev-server
Recent versions of Webpack & WDS need webpack-cli package, I recommend you to downloaded if your Webpack version is 4 or higher
first I've install webpack-dev-server in global
npm install -g webpack-dev-server
after installation I got this error..
Error: Cannot find module 'webpack'
this is version not matching problem, in my code I used these dependencies
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"babel-preset-es2015": "^6.24.1",
"webpack": "2.2.0-rc.3",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "2.1.0-beta.0",
"webpack-validator": "^2.3.0"
},
so change webpack-dev-server version in global
npm install -g webpack-dev-server#2.1.0-beta.0
in my case this was worked
Check your node version, in my case switching to last node version helped.
I solved this problem by typing command: npm update