'npm run build' in linked dependency breaks the running react app - node.js

it seems that rebuilding a local linked dependency breaks the main package that is running with react-scripts-ts start with a "not found" for file dist/index.js of the linked module.
This is not happening in Mac OSX where after linked local module is rebuild, the running react-app automatically reloads with no problems.
In Ubuntu you have to stop the react app and run "npm run start" again.
Any clue?

Related

Node.js is causing error: Missing script: "start"?

I just started studying front-end development and I'm struggling with a node.js error.
Typing 'npm start' in my VSCode terminal used to work fine for simple tutorial projects with just an index.html, script.js, and style.css file. (without a package.json file)
However after trying out React for the first time, 'npm start' now doesn't work anymore in my other non-React projects. At first it was giving me an error that it was missing the package.json (which it didn't need before?) but after trying to fix it with help of googling I now got to a point where it's giving me the error: Missing script: "start".
How can I run node without creating package.json files for every small tutorial project I've made previously, or without turning them into React apps? Also why is this happening? Did installing React-native create dependencies of some sort?
Thanks in advance!
I already tried reinstalling node.js and tried different versions. Also tried deleting package-lock.json. It still works for React apps, just not with simpler native javascript apps.
A package.json file is required if you want to install any packages or run scripts in your terminal. In your package.json file, make sure you have added scripts property. This is an example of how you can use it:
{
...
"scripts": {
"start": "react-scripts start"
}
}
Remove ... from the snippet if you're copying, this has been added to indicate that there are one or more fields in this JSON file.
After you have added this to your package file, you will be able to run the start script by typing npm run start in the terminal or if you use Yarn: yarn start.
Edit:
You said that running npm start in your React project is running fine, but on your simpler projects with only a simple HTML, CSS and JS file is not working when using the script.
You are probably confusing npm start with node file.js. Where node file.js doesn't require a package to be in your project to run a JavaScript file, using npm start requires you to have a JSON file present in your project folder with the JSON code as in my answer.
So long story short: Using npm start requires package.json with the script property available. While node file.js doesn't require you to have this file in your project.
if you are using react-native you can do the following
First you have to build your project with the command
npx react-native run-android , npx react-native run-ios
Once your project has build successfully and app is installed on your device then you your development server is started already. for some reason if your server is closed then you can run it with the command given below.
adb reverse tcp:8081 tcp:8081 this will send a signal to your device and after this run npx react-native start

Nestjs "Reached heap limit Allocation failed - JavaScript heap out of memory" on npm run build

I have an issue with my Nest js API.
When I build in local, all works fine and I can build and start the development server without problems, but when I go to my server I can't build or start the development server.
When I try to run "npm run build","yarn build" or start the server with "yarn start" the node returns to me this error:
I tried to run "export NODE_OPTIONS=--max_old_space_size=4096" and in the ~/.bashrc export de node options with more space. Also, i upgraded all dependencies, and deleted and installed again, but nothing works. I have the same issue with the frontend of this project that uses Next JS.
The server is an aws EC2 t3.small server with Ubuntu 20.04.3 LTS, the node version is v17.3.0, the npm version is 8.3.0 and the yarn version is 1.22.17.
When I run "tsc --extendedDiagnostics --noEmit" i have 20 errors from node_modules/#nestjs/config, I tried to update the package but doesn't work:
And finally, I get this summary:
Thanks
Well, after few hours searching a solution I updated the nest project with the command "sudo nest update --force", I removed the node_modules and executed "yarn install".
After this, I granted all the permissions to my project files with "sudo chmod -R 777 ./" and finally the "npm run build" and "yarn build" worked.
Thanks a lot!

NestJS server dies when console is closed?

I created folder for project, copy package.json and run npm install, build locally nestjs project and copy dist into server. Then ran in console node dist/main.js. For testing I used a base NestJS project (nest new ...) which only return "Hello word" on 3000 port.
Server work fine, but after close of console will stop.
I think problem on VPS (Ubuntu) settings or may be need to add some parameters to NestJS.
Why it not work constantly?
Thanks in advance for any advice.
I resolved problem with npm forever - https://www.npmjs.com/package/forever
install it globally - npm install forever -g
then got to project dir and run - forever start dist/main.js
Seems all work fine.

React with Express application using "pm2 start" always shows status as errored

I have a React app with Node as the server and I am writing my code in ES6 and transpiled using babel. I am using Windows OS. I was using NodeMon for watching changes it worked fine in development. I am making a production configuration for the app and thought of using PM2 for both dev and prod.
Below is the script in my package.json,
"scripts": {
"dev": "pm2 start --watch --interpreter babel-node src/server/server.js --name appDev",
...
"prod": "pm2 start build/server/server.js -i max --name appProd"
}
I have ES6 code in my src folder and transpiled ES5 code in build folder. "prod" command works fine if I remove "-i max" [infinite command prompts started opening up with "-i max". Hope it will be fine in server after deployment].
Now the problem is, "dev" script is always resulting in "errored" status and when I check status error logs are empty.
ANy idea what's going on? I will run NodeMon in dev and PM2 in prod for now but why PM2 has issue with ES6 and --interpreter babel-node?
Update:
I have tried --interpreter babel-cli after installing globally, it failed with an error [PM2][ERROR] Interpreter babel-cli does not seem to be available. I have babel-cli globally and locally.
Even pm2 start app.js --interpreter ./node_modules/.bin/babel-node didn't work.
I had issues deploying with the latest (12.16.2) version of node. I was having issues with ES6 and imports. I understand there are more complex solutions that can solve that issue, but backing up to node 12.4.0 solved that issue for me. NOTE: Node 12.4.0 is an earlier release than 12.16.2. I picked version 12.4.0 because that is what Digital Oceans "Node" servers are initialized with. I figured that their server guys probably know far more about it than I, and just decided to cheat off their test, so to speak.
I am having no issues with 12.4.0, and you can easily download an earlier version off of the node website. If you plan to install it on a Linux server, I would recommend using nvm. I had used nvm to go back to 12.4.0, and still had issues (I am sorry I forget specifics). I just redid the server from a fresh image with plain Ubuntu 18.04 LTS and am good on that at this time. Even with the local Windows install of node that I use to develop, I had to do a full uninstall and a clean install to avoid issues. Highly recommend this route if able.
Good luck.

execute ng serve pointing to the angular directory from current directory

working with angular2 App, and i am writing .bat scripts to automate the angular build and serving the application, as part of the ng serve. I have to do like
c:\abc\edf>ng serve --server=d:\angualr2\demoApp
Here demoApp is angular2 and node_modules already installed i need to up the angulap app by my batch script.
Where as everyone knows it works and working for me too.
d:\angualr2\demoApp>ng serve
if you build the application, then you don't serve it with ng serve
the flag --server is unknown to me, and to the CLI documentation (--help)
If you have a path issue, start by goign into the right folder of your file explorer with cd D:\angular2\demoApp (not sure about it, I'm more of a Linux man)
ng works because NPM added it to your PATH. If you work on another computer, it won't work. Consider running with the local package with a npm command such as npm run build, where build: "ng build --prod"

Resources