vuejs got syntaxError when production buid - node.js

I'm developing Vuejs project with Vuetify UI framework.
After I run npm run build on the server (AWS), I got Uncaught SyntaxError: Unexpected token and the project show white screen.
Then I try to do npm run build on my laptop, but everything work fine.
I would like to know this error cause of the server environment? or any issue. And how to fix it?
Regards.

It looks like your server is serving some HTML page in place of your JavaScript files. Open one of the .js files that the errors are coming from and look at its contents. It's probably a 404 page being incorrectly served with a 200 status, or something equivalent to that.

Related

why am I getting this "Cannot find module server.js"?

I had a Traversy Media tutorial on how to learn the MERN stack that I was following. I had the first part installed on my desktop and it was working properly. opened it back after two weeks and I am getting '/Users/mohamedsoliman/Desktop/Traversy Media/backend/server.js'
the problem here is that the folder structure should have a "backside folder" so server.js should be at "'/Users/mohamedsoliman/Desktop/Traversy Media/backend/backside/server.js'"
Not sure how can I fix this or if that's the only problem I have here ?
This image shows the directory structure I have for the project
This image shows the error I am getting
Your code is currently nodemon backend/server.js, but it should be nodemon backend/backside/server.js.
It looks like your server.js is your entry point for the app.
In that case, run the app as follows,
node backend/backside/server.js

Error running node in cloud9 IDE?

First i got the following error and i couldn't figure yet what is this about:
any idea?
The problem is that you're trying to open an HTML file with Node.js.
Node.js is supposed to run JavaScript code (typically stored in .js files) and it cannot parse your HTML file, which is why you're getting these errors.
You could try executing the files called app.js or server.js with the following commands:
node app.js
or
node server.js
Also, it seems your project (or whatever it is you're working on) has a README.md file which could help to clarify where you're supposed to start.

Trying to get MEAN maps to work on windows

I cloned this mean map that I watched on a azure mongodb video , and I did the same steps in the readme like they did
https://github.com/scotch-io/mean-google-maps
So
npm install
node server.js
// I didn't do any mongodb , as there is a config.js that is pointing at an amazon mongodb.
On the video they didn't do any mongodb locally
I see that in chrome console it throws an error with modernizr
#!/usr/bin/env node
That line is red squiggly , it that line causing the map to not load? Is that even going to work on a Windows 10 machine I'm running?
This error has nothing to do with mongodb.
The problem is the Modernizr link in the public/index.html (line 18) points to a script which is designed to be run server side.
The shebang #!/usr/bin/env node indicate a javascript file that must be run with Nodejs. Your browser can't run this kind of script.
It's looks like a confusion in bower dependency management.
(I think it is generaly not a good practive to include bower_components directory into git repository)
Maybe you can try to fix it by replacing the link with a cdnjs version of Modernizer:
https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js
Or just delete the line, you use a recent Chrome browser after all...

Problems with webpack build, using angular-cli

I am using angular-cli with built-in webpack and encounter the following problem: if I use ng serve --host 0.0.0.0 --port 3000 everything works fine, but when I try to build the app (no matter developer mode or production) with ng build and then put it into my nginx, not a single route works and every attempt of browser to download image, which is used on start page, ends with 404 error. What am I doing wrong? Googled a ton of stuff and nothing seems to be a solution.
Some additional info:
angular-cli: 1.0.0-beta.21
node: 6.9.4
os: win32 x64
So for everyone who encounters this problem, after some research I found this:
1) To solve problem with styles not loading properly, add encapsulation: ViewEncapsulation.None to each of your components #Component() decorator, this way it's going to bundle styles properly. More info here: https://angular.io/docs/ts/latest/guide/component-styles.html#!#loading-styles
2) Make sure all your images are stored inside assets folder. If you store them in some other folder like images, just put that images folder inside assets
3) And for information about paths not working on page reload, have a look at this question and read some information about strategies: Angular 2 : 404 error occur when i refresh through Browser
Also this link has config examples https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Including socket.io.js results in undefined 'require'

I've just started with node.js and socket.io.
I installed node.js using the windows installer, resulting in the following install path:
C:\Program Files (x86)\nodejs
I used npm to install socket.io and managed to include this in my server file, which is located in my projects folder, under
D:\projects\node\nodeserv.js
I then included the socket.io.js, which is located under the same socket.io folder, under the nodjs folder.
However, when I try to open the HTML file containing the client code, I get an error in socket.io.js stating:
Undefined reference to 'require'
Can someone help me out and see what I am doing wrong?
Make sure to check your spelling very carefully. If you can post post some code to look at, we can probably tell you the problem right away. More than likely it's a simple typo.
It sounds like you are trying to run node.js from the browser. Node.js runs on the server with the node executable. When you open the HTML file in your browser, it will execute the Javascript on it in a non node.js environment.
Apparently you need to get the socket.io.js file from the nodejs server.
So instead of an include, use an async call to get the file, like:
$.getScript('http://localhost:1337/socket.io/socket.io.js', function(){
//You can now use the io namespace
});

Resources