Next JS : Error: EPERM: operation not permitted, open - reactjs

I am trying to build the next Js app production files to deploy it on cPanel, when I execute
npm run dev the app is working just fine but as I start to build a production file with the help of this video(https://youtu.be/1ykSXau838c) and executes npm run build it gives me an error in the terminal as given below:
PS C:\Users\hp\Desktop\reactJs-project\NextJs\test-app> npm run build
> test-app#0.1.0 build
> next build
info - Checking validity of types
info - Creating an optimized production build .node:events:368
throw er; // Unhandled 'error' event
^
Error: EPERM: operation not permitted, open 'C:\Users\hp\Desktop\reactJs-project\NextJs\test-app\.next\trace'
Emitted 'error' event on WriteStream instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'C:\\Users\\hp\\Desktop\\reactJs-project\\NextJs\\test-app\\.next\\trace'
}
so I just want to know is there any way to solve this problem?

Posting comment from Koronag as an answer (as it helped me with this error and seems the most likely cause)...
This error is commonly seen when running a build while the dev server is already running. (E.g. in my case, I had a local build running via npm run dev and was trying to commit/push code, which invoked a Git Hook that also runs npm run dev.)

For me, it works fine this answer drives me to the resolver.
I run 2 scripts in terminals:
once for development
another for the build process.
So after killing the development script it looks perfectly fine!

From next-sitemap repo README.md
"Having next-sitemap command & next-sitemap.js file may result in file opening instead of building sitemaps in windows machines.
As a solution to this, it is now possible to use a custom config file instead of next-sitemap.js. Just pass --config .js to build command."
Next-Sitemap README.md - Building Sitemaps
The above worked for me

Related

Ionic build failed without specific error

After cloning my Ionic React project to my server, I ran npm install and all dependencies were installed as expected.
But when I tried to build my app running sudo ionic build --verbose, it tooks much more time than usual and ended like this :
eslint:lint-result-cache Persisting cached results: /var/www/html/ms-users-front/node_modules/.cache/.eslintcache +0ms
eslint:cli-engine Linting complete in: 4827ms +48ms
//It stay here for at least 10min before to failed while it tooks 1min in my local machine.
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
[ERROR] An error occurred while running subprocess react-scripts.
react-scripts build exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 1 functions +1ms
ionic:utils-process processExit: exiting (exit code: 1) +44ms
My server is an ec2 instance with httpd installed and everything was working great before I tried to build a new version yesterday.
With exactly the same process, the app is building perfectly on my local machine...
I tried npm update, delete eslint cache, and build but without success.
I tried to downgrade Typescript to 4.1 because I had a warning saying that Typescript should be >4.5 and it was 4.7. But after some tests on local, it looks like this has no incidence on the build process.
I'm totally stuck and I absolutly don't know what to try.

Github deploying issues

When I try to use npm run deploy on github, it throws me the following errors:
fatal: bad object refs/remotes/origin/main
error: github.com:Aris-Empanta/Accountant_landing_page.git did not send all necessary objects
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: bad ref for .git/logs/refs/remotes/origin/main
fatal: bad object refs/remotes/origin/main
fatal: failed to run repack
error: task 'gc' failed
Any suggestions?
Though VS code command line, everytime I change my project I push the changes you know, git add, git commit, git push origin. After that when I confirm the merging from github, I write npm run deploy to deploy the changed project to gh-pages. It was working, but suddenly stopped.

Module not found: Can't resolve './.htaccss' after installing React-boilerplate Dandelion starter project

I have downloaded Dandelion starter-project and decompressed it on a local folder. I ran:
npm i
npm run build:dll
and then
npm start
then it complains:
> dandelion_pro#1.6.1 start /home/......./dandelion/starter-project
> cross-env NODE_ENV=development node server
Happy[js]: Version: 5.0.1. Threads: 5 (shared pool)
Server started ! ✓
Access URLs:
-----------------------------------
Localhost: http://localhost:3001
LAN: http://xxx.xxx.xxx.xxx:3001
-----------------------------------
Press CTRL-C to stop
Webpack is building script...
Happy[js]: All set; signaling webpack to proceed.
Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`
webpack built 920e70412c607c0d50a6 in 3600ms
✖ 「wdm」:
ERROR in ./app/app.js
Module not found: Error: Can't resolve './.htaccess' in '/home/......./dandelion/starter-project/app'
# ./app/app.js 27:0-48
# multi ./node_modules/react-app-polyfill/ie11.js webpack-hot-middleware/client?reload=true ./app/app.js
I have searched the web looking for a solution, but I was unable to find one. My system is a Ubuntu 18.04.3 based machine running Linux Mint 19.3, nodejs 12.15.0 and npm 6.13.4. How can I solve this?
Well folks after an endless unsuccessful search on the web I created an empty ´.htaccess´ file and placed it into the ´app´ folder. Maybe this is not the better or the elegantest way to do it, but it worked for me.
I am posting this hoping it might be helpful.

Deploy React JS SPA in Openshift

I have build a React JS app and triggered yarn build command. Its builded successfully and if I run yarn global add serve, its working perfectly on http://localhost:5000. After that I tried below link to deploy this code to OpenShift.
OpenShift Deployment
According to the document, I tried to run npx nodeshift --strictSSL=false --dockerImage=bucharestgold/centos7-s2i-web-app --imageTag=10.13.0 --build.env YARN_ENABLED=true --expose
Then I got this log -
npx: installed 216 in 37.284s
kubernetes-client deprecated require('kubernetes-client').config, use require('kubernetes-client/backends/request').config. ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\node_modules\openshift-rest-client\lib\openshift-rest-client.js:25:35
kubernetes-client deprecated require('kubernetes-client').config, use require('kubernetes-client/backends/request').config. ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\node_modules\openshift-rest-client\index.js:23:39
2019-12-21T11:58:07.841Z INFO loading configuration
kubernetes-client deprecated fromKubeconfig see https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md#request-kubeconfig- ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\lib\nodeshift-config.js:35:32
2019-12-21T11:58:07.882Z INFO using namespace smart-learner at https://c101-e.jp-tok.containers.cloud.ibm.com:30512
kubernetes-client deprecated Client({ config }), see https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\node_modules\openshift-rest-client\lib\openshift-rest-client.js:95:18
kubernetes-client deprecated Request() without a .kubeconfig option, see https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\node_modules\kubernetes-client\lib\swagger-client.js:200:19
2019-12-21T11:58:07.928Z WARNING a file property was not found in your package.json, archiving the current directory.
2019-12-21T11:58:07.929Z INFO creating archive of .gitignore, build, Dockerfile, package-lock.json, package.json, public, README.md, src, yarn.lock
2019-12-21T11:58:09.001Z INFO using existing build configuration smartlearner-s2i
2019-12-21T11:58:09.377Z INFO using existing image stream smartlearner
2019-12-21T11:58:09.378Z INFO uploading binary archive C:\ReactAPP\smartlearner/tmp/nodeshift/build/archive.tar
2019-12-21T11:58:15.825Z INFO binary upload complete
2019-12-21T11:58:15.828Z INFO waiting for build to finish
kubernetes-client deprecated .getStream use .getByteStream, see https://github.com/godaddy/kubernetes-client/blob/master/merging-with-kubernetes.md ..\..\Users\RITUPARNABHATTACHARY\AppData\Roaming\npm-cache\_npx\11068\node_modules\nodeshift\lib\build-watcher.js:56:107
2019-12-21T11:58:19.798Z TRACE Using bucharestgold/centos7-s2i-web-app:10.x as the s2i builder image
2019-12-21T11:58:20.550Z TRACE ls: cannot access /tmp/src/node_modules: No such file or directory
2019-12-21T11:58:20.564Z TRACE ---> Installing application source
2019-12-21T11:58:20.585Z TRACE ---> Building your Web Application from source
2019-12-21T11:58:20.592Z TRACE Current git config
2019-12-21T11:58:20.620Z TRACE url.https://github.com.insteadof=git#github.com:
2019-12-21T11:58:20.629Z TRACE url.https://.insteadof=ssh://
2019-12-21T11:58:20.629Z TRACE url.https://github.com.insteadof=ssh://git#github.com
2019-12-21T11:58:20.630Z TRACE ---> Using 'yarn install' with YARN_ARGS
2019-12-21T11:58:21.356Z TRACE yarn install v1.10.1
2019-12-21T11:58:21.594Z TRACE warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
2019-12-21T11:58:21.657Z TRACE [1/4] Resolving packages...
2019-12-21T11:58:23.111Z TRACE [2/4] Fetching packages...
2019-12-21T11:58:53.081Z TRACE error #typescript-eslint/eslint-plugin#2.10.0: The engine "node" is incompatible with this module. Expected version "^8.10.0 || ^10.13.0 || >=11.10.1". Got "10.12.0"
2019-12-21T11:58:53.083Z TRACE error Found incompatible module
2019-12-21T11:58:53.086Z TRACE info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2019-12-21T11:58:58.441Z TRACE error: build error: non-zero (13) exit code from bucharestgold/centos7-s2i-web-app:10.x
2019-12-21T11:59:00.497Z ERROR build failed with message: Assemble script failed.
2019-12-21T11:59:00.503Z ERROR Assemble script failed.
i am not able to understand what I am missing here. I found that bucharestgold/centos7-s2i-web-app has been depreicated and tried with npx nodeshift --strictSSL=false --dockerImage=nodeshift/ubi8-s2i-web-app --build.env YARN_ENABLED=true --deploy.env NPM_RUN="npx yarn start" --deploy.port=3000 --expose. This is also throwing same error message.
You can use the new web-app flag feature and let nodeshift set the appropriate docker image.
Try running this command instead npx nodeshift --web-app --build.env YARN_ENABLED=true --deploy.env NPM_RUN="npx yarn start" --deploy.port=3000

npm start on new create-react-app build returns ELIFECYCLE error

Made a new react app using create-react-app and now getting the following error in the terminal when running npm start:
> react-scripts start
Attempting to bind to HOST environment variable: x86_64-apple-darwin13.4.0
If this was unintentional, check that you haven't mistakenly set it in your shell.
events.js:167
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
Emitted 'error' event at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1468:12)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aqi#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aqi#0.1.0 start 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! /Users/chris/.npm/_logs/2018-12-24T10_07_46_970Z-debug.log
Tried removing the node-module folder and npm install.
type unset HOST in the terminal. It will solve the issue.
I struggled with this exact issue for an entire day. If you do unset HOST, it will solve it, but temporarily. The simple solution to this bug is as follows (this is for Mac, for Window the commands may differ):
Open your bash with the following command: open ~/.bash_profile
Write this down (exactly what it says) all the way down the file once the file opens: HOST="localhost"
After that, save the file and quit (Command + q)
Finally, reload the environment by typing this on the terminal:
source ~/.bash_profile
If you do all the steps correctly, this should resolve the bug.
Mostly the problem occurs when you set a specific hostname instead of regular used one localhost.
On Mac/Linux terminal run hostname, you will receive the specified hostname. If it's something different than localhost refer to your bash profile config file (ie for ZSH it's .zshrc, or for Bash it's .bashrc in your home directory); and if HOST=localhost exists in the profile comment it.
PS: do not forget to restart your terminal to make the change takes effect.
I also struggled with this. Many online solutions only solve the first part. Here I'll provide my approach to fully solve the issue and make npm start work
Understand the issue:
There are 2 parts to the problem. First, you want to set your environmental variable, HOST, to "localhost". You can do it by typing in your terminal (anywhere):
nano ~/.bash_profile
In the bash file, type HOST="localhost" in a new line and type: export HOST. This directs your program to go to this HOST by default
Save change by Ctrl + X, then press Y (Yes), then press Enter
Return to your terminal, run: source ~/.bash_profile to refresh the terminal
Now, your computer has updated its HOST variable to localhost. You can check that by typing: env | grep HOST in the terminal. Grep means to grab that variable in the variable list.
Hopefully that solves the issue fully. If you then encounter: dyld: lazy symbol binding failed.
This simply means there's something wrong with the fsevents. Why? I am not sure, but a sure fix is by deleting the node_modules/fsevent files from my search. A permanent fix is to remove the node modules and re-do the npm install. Make sure that fsevent is version 2.0+!
Hope that helps. This surely took some time to debug!
References:
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
https://medium.com/#choy/fixing-create-react-app-when-npm-fails-to-start-because-your-host-environment-variable-is-being-4c8a9fa0b461
https://medium.com/#youngstone89/setting-up-environment-variables-in-mac-os-28e5941c771c
I was able to fix the similar error by running npm install create-react-app instead of npm install -g create-react-app. Hope it helps.
you should create .env files
https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables#adding-development-environment-variables-in-env
read this Environments in Create React App
https://serverless-stack.com/chapters/environments-in-create-react-app.html
unset HOST
This worked for me, if not, then run the code and give it a reboot
I ran into this issue because I usually had anaconda running as default in the terminal. So my login is not just my computer login account but appending with some string created by conda. (eg xxx#xxx)
However, in order to get the react server up and running normally you will need to have your login as your computer login id. (eg xxx#)
There are two solutions to achieve this.
to run unset HOST, it will get rid of the string at # of your terminal log in id.
to add HOST as env var to your terminal config file. For zsh user (most likely cos mac now run zsh as default in the terminal) You need to add export HOST="localhost" or export HOST="" to ~/.zshrc and run source ~/.zshrc in the terminal to refresh the new zsh config. You can do the same to bash config file by following one of the answers above.
GOOD LUCK.
Attempting to bind to HOST environment variable: x86_64-apple-darwin13.4.0
If this was unintentional, check that you haven't mistakenly set it in your shell.
This issue comes once we write npm start in terminal, to rectify the issue in your terminal before executing the command npm start write unset HOST then write the command npm start it works fine and you can check on localhost://3000

Resources