app.use(noopServiceWorkerMiddleware('/'));
For me(and probably most of you) the service worker is served at the root of the project. In case it's different for you, you can pass your base path instead.
–
I've also faced this problem and figure out it by upgrading the react-scripts
package from "react-scripts": "3.x.x"
to "react-scripts": "^3.4.1"
(or the latest available version).
Delete node_modules\
folder
Delete package-lock.json
file
Rewrite the package.json
file from "react-scripts": "3.x.x"
to "react-scripts": "^3.4.1"
Install node packages again npm i
Now, start the project npm start
And it works!!
–
I just had this issue after installing and removing some npm packages and spent almost 5 hours to figure out what was going on.
What I did is basically copied my src/components in a different directory, then removed all the node modules and package-lock.json (if you are running your app in the Docker container, remove images and rebuild it just to be safe); then reset it to my last commit and then put back my src/components then ran npm i
.
I hope it helps.
We ejected from react-scripts
and so could not simply upgrade the package.json entry to fix this.
Instead, we did this:
in a new directory, create a new project -> $> npx create-react-app foo-project
and then eject it -> cd ./foo-project && npm run eject
now copy the files from /foo-project/config into the config directory of our main app and fire up your dev server
hope this helps others in a similar bind.
–
Go to you package.json
Change "react-scripts": "3.x.x" to "react-scripts": "^3.4.0" in the dependencies
Reinstall react-scripts: npm I react-scripts
Start your project: npm start
If you ejected and are curious, this change on the CRA repo is what is causing the error.
To fix it, you need to apply their changes; namely, the last set of files:
packages/react-scripts/config/paths.js
packages/react-scripts/config/webpack.config.js
packages/react-scripts/config/webpackDevServer.config.js
packages/react-scripts/package.json
packages/react-scripts/scripts/build.js
packages/react-scripts/scripts/start.js
Personally, I think you should manually apply the changes because, unless you have been keeping up-to-date with all the changes, you could introduce another bug to your webpack bundle (because of a dependency mismatch or something).
OR, you could do what Geo Angelopoulos suggested. It might take a while but at least your project would be in sync with the CRA repo (and get all their latest enhancements!).
In my case, it was because I (at one point) had reactn
installed, which also includes its own version of React (for some reason).
After that had been installed (even after uninstalling again), this error occured.
I simply removed node_modules
and ran npm install
again, and it worked.
this has nothing to do with react
, as the error specified, undefined is not accepted as the path argument. make sure you don't pass a variable to path.join that happens to be undefined or null.
for example:
const {path} = require('path');
let arg = undefined;
let mypath = path.join(__dirname, arg);
// The same error would occur.
Create a new React app through create-react-app
.
Eject it through npm run eject
or yarn eject
.
Install all the packages that are missing from the package.json
.
Copy your src folder assuming all your code is situated in this folder.
Redo your changes on the config and script folders, if needed.
Worked for me.
I tried various approach described above but none of them worked since I have ejected my css. Finally applying following steps helped:
Upgradereact-scripts
from "react-scripts": "3.x.x"
to "react-scripts": "^3.4.0"
Downgrading react-dev-utils
form "react-dev-utils": "^10.x.x"
to "react-dev-utils": "10.0.0"
Delete node-modules
folder and package-lock.json
/yarn.lock
Reinstall packages npm install
/yarn install
I didn't want to upgrade react-scripts
, so I used the 3rd party reinstall npm module to reinstall it, and it worked.
npm i -g npm-reinstall
reinstall react-scripts
If you have an ejected CRA, there are a few changes to the webpack-dev-server config that if left unchanged will throw this error. Comparing a freshly ejected CRA 4.x config to my CRA 3.x config showed a number of changes to functions that didn't previously accept arguments that now do.
In my case, one of the breaking changes was the addition of a path to their noopServiceWorkerMiddleware
function. Adding in the missing path noopServiceWorkerMiddleware(paths.publicUrl)
fixed this for me.
Simply upgrading react-scripts
version solved my issue.
react-scripts
package from "react-scripts": "3.x.x"
to "react-scripts": "^3.4.1"
(or the latest available version).
Avoid deleting package-lock.json
straightaway. First try this, if it doesn't work then proceed further.
remove the whole node_modules folder.
remove the package-lock.json file.
run command npm install npm-install
as shown in the image:
Here we go.. npm start...wao
I had the same issue running it in my pipeline.
For me, the issue was that I was using node
version v10.0.0
in my docker container.
Updating it to v14.7.0
solved it for me
None of the other solutions worked for me.
However, adding this to my package.json fixed the issue for me:
"resolutions": {
"react-dev-utils": "10.0.0"
I was having the exact same issue for a gatsby blog. The dependencies couldn't be upgraded and could only run on npm version 10.22.1.
What works for me is the following:
#!/bin/bash
rm -rf .cache
rm -rf public
gatsby build
gatsby serve
Basically the completely rebuild everything, and this error is gone. Very annoying but at least it builds.
What's ever more weird is that, if I tweaked the image of the blog post, e.g., resizing it a bit, it builds. I have absolutely no idea why. But that least that's a clue.
If you are finding it difficult to show up an image in you react.js file, I tried searching on youtube.
It suggests adding image inside 'public' folder(rather than 'src' folder).
Although still looking for reasons why adding images inside 'src' folder didnt worked out.
link:
https://www.youtube.com/watch?v=taMJct5oeoI&ab_channel=EsterlingAccime
https://daveceddia.com/react-image-tag/
In my case, I previously changed the folder path, and then only I got that error when using npm start
.
So, I changed the folder path C:\Users\User\Documents\### Coding\todo-app
into C:\Users\User\Documents\Coding\todo-app
and then it worked.
I think the problem was using those special characters in the folder name.
A very similar (misleading) error also occurs when running the react-native bundle
command without arguments.
Provide both --entry-file
and --bundle-output
for a successful run:
react-native bundle --entry-file ./index.js --bundle-output ./index.jsbundle