Webpack build working on local but fails on server - javascript

I am trying to deploy an app that works on local but when I put it on the server I get this error that refers to a filter function on an array. Indicating that the compile ES5 JS is broken somehow.
I use the webpack build command and the output works on my local but when I am putting it on the server I get this on the browser:
`TypeError: s.filter is not a function vendor.bundle.9a44edfc.js:2:131513`
I don't understand why it would work on my local and not on the server, is the same node, npm and yarn version on both.
I run this command for build
"build": "webpack --config webpack/webpack.config.babel.js",
"dev": "webpack serve --env mode=dev --env isDevServer --env NODE_ENV=local --config webpack/webpack.config.babel.js"

It had nothing to do with webpack, I was getting some data by requesting a route to my express server and I used:
axios('api/projects')
Instead of
axios('/api/projects')
And just for that it failed to get the data, the funny thing is that on my computer I am using nginx 15 on mac, and on the server I am using nginx 14 with Ubuntu and on my computer it did not failed.

Related

Bitbucket does the build somehow differently?

I use nodejs 14.18.1 locally and in the pipeline, a few days ago a part of the frontend started to fall off with the error "ReferenceError: Cannot access 'z' before initialization", there are no errors in the code, also the local build works, and we even uploaded it on s3 as a temporary solution, but after building via bitbucket, an error appears.
script:
- cd client
- npm install
# CI=true in default variables for Bitbucket Pipelines https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/
- npm run build:br
npm run build below
"build:br": "webpack --env REACT_APP_LANGUAGE_TYPE=BRAZIL --mode production",

What is the --watch and --debug option in nest start

I read following documentation described nest command.
https://docs.nestjs.com/cli/scripts
According to the document, following must be added to package.json
"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
What are the --watch and --debug options?
According to the nestjs start docs the actual uses are as follows;
--watch
Run in watch mode (live-reload)
Alias -w
Source files which are saved with changes are automatically compiled without the need to manually run npm run start to trigger webpack compilation after every change.
For example, typescript files with changes (on save, or when using git) in src will be compiled to javascript files in dist (depending on your setup)
--debug
Run in debug mode (with --inspect flag)
Alias -d
The --debug flag actually runs the node process using the --inspect flag to allow native debugging using an IDE or otherwise. Once the node process is running, you can use an IDE to connect to to the node debug address and port (default 127.0.0.1:9229) and use breakpoints* to pause execution.
*However, do note that the above at present isn't completely accurate. IDEs usually need the --inspect-brk flag (for breakpoints) and it seems there is still a problem with the nestjs implementation.
Some IDEs (for example VS Code) can get around this with an auto-attach feature and it seems --debug is not even needed. Although very easy to set up, it is not as streamlined when developing multiple running node apps.
In general, --watch means the terminal will stay open and watch for any file changes and then reload the server. --debug means it will log more messages to the console (e.g. info or warnings), which can be helpful for debugging.

Difference between" npm run serve" and "npm run dev" in vuejs

What is the difference between npm run serve and npm run dev in vuejs. Why should i use npm run serve command to run the project
npm run serve basically is just saying "npm please run the command I defined under the name serve in package.json" the same happens with npm run dev.
Given this the commands can do the exact same thing, similar things, or very different things. Usually they are a shorthand for running a dev server on localhost, but it’s not a rule, only a convention.
So you'll need to check in your package.json file and look for
"scripts": {
"serve": "[list of commands here]",
"dev": "[list of commands here]"
},

About MEAN 2 stack using angular-cli

I'm studying MEAN 2.0 . I need to do "ng build" before running "node server.js".
I would like to ask if do I need to do (ng build) everytime I changed something in my angular side? Because when I'm using only angular-cli, when I changed something and my server is still running. It will show the changes. I tried to change something but when I re-run my node server nothing happens.
Yes you need to do ng build before running node server.js.
ng serve :- serves on a server,
node server.js :- doesnt serve on the same port, it runs on the port you define in your server.js, it reads from the build folder, which will need updated fies.
Live reload wont work :(
You can
1. write tasks for it
2. write script in package.json which does ng build && node server.js
If you arranged your folder structure to be:
|_server
|_ server.js
|_ public (angular-cli project)
|_ dist
|_ src
|_ package.json (client)
|_package.json(server)
Considering you've the default angular-cli package.json,
Add concurrently using npm:
npm install concurrently --save-dev
All you would need is to add those scripts in server package.json:
"scripts": {
"client":"cd public && ng build",
"server":"ndoe ./server/server",
"start":"concurrently --kill-others \"npm run client\" \"npm run server\""
}
Now, all you have to do is:
npm run start

NodeJS - nodemon not restarting my server

I installed NodeJS (4.4.5) and then proceed to install nodemon (1.9.2) as well,
I follow all the instrucctions of instalation (npm install -g nodemon)
I created a new folder, inside I have my server.js with some basic code:
var http = require('http');
http.createServer(function (request, response){
response.writeHead( 200, {'Content-Type': 'text/plain'} );
response.write("Hello world");
response.end();
}).listen(3000, 'localhost');
console.log('http://localhost:3000');
So when I run in my console "nodemon server.js" I get this:
[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
http://localhost:3000
(Which means that is running fine)
But when I make some changes in my server.js, It doesn't restart the server
What could be the issue?
In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enabled Chokidar's polling.
Via the CLI, use either --legacy-watch or -L for short:
nodemon -L
I had the same issue on nodemon 1.9.2 : 0 files were watched by nodemon
(try verbose mode nodemon server.js -V to get more information)
After some research, this issue was due to my root directory name :
My root directory was named "mysite.git" thus nodemon was watching 0 file. I had renamed my root directory without the dot and nodemon now works as expected.
Remove all special characters from your root directory and nodemon should work as expected.
You can try running like this nodemon -L yourapp.js, something like that:
"scripts": {
"start": "node index.js",
"dev": "nodemon -L index.js "
}
And run command:
npm run dev
This worked for me!
I just hit what seemed to be the same issue where I would make changes to my code and save them but nodemon wouldn't restart my server. The only way I could update was via 'rs' in the console. I ended here looking for a solution but then decided to just re-install nodemon as there was no good explanation for why it wasn't working:
npm uninstall nodemon
npm install nodemon
After reinstalling the automatic restart on code change worked.
Nodemon uses SIGUSR2 signal for restarting the server, cross-check if your server is overriding the functionality of this process signal.
In my case, I was using heapdump module, which was resetting this signal, hence I started the server using:-
env NODE_HEAPDUMP_OPTIONS=nosignal nodemon app.js
This worked for me.
Edit the package.json file like this :
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js",
},```
This may help you.
Just Make Sure to add to scripts -> start --legacy-watch ./app
"scripts": {
"start": "nodemon --legacy-watch ./app ./bin/www "
},
I had the same problem. I tried uninstalling nodemon, didn't work. You can try and uninstall nodemon globally, if it works. It didn't work in my case, so what I did is I deleted all the node modules from my system. They will be located at C:/users/user/AppData/Roaming/npm. I even reinstalled node into my system and then installed nodemon, then it worked.
I had the same problem and I solved it adding the path C:\Windows\System32 to the system environment, after that, I had to restart Visual studio code and it worked!...
Reference: https://www.youtube.com/watch?v=a9fIZViTNEA
if you are on windows use Powershell, not WSL. If you want to use WSL, you have to move your project directory to the WSL home directory OR use nodemon -L on the command line.
solve it by adding the path
C:\Windows\System32
to the system environment
Source: https://www.youtube.com/watch?v=a9fIZViTNEA
I found a solution on YouTube. So, the solution is:
Copy this path:
C:\Windows\System32
Go into 'computer/This Pc' properties then into 'Advance System Settings/System Settings'.
Then click on 'Environment variable' Button.
Then double click on 'Path' in User Variables section.
Then click on 'New' and paste this path :
C:\Windows\System32

Categories