Application has thrown an uncaught exception and is terminated: SyntaxError: Use of const in strict mode.
at Module._compile (module.js:434:25)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\mongoose\index.js:7:18)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
Error is thrown everytime Azure Web App project is made and an Express App is published. I tried with Azure Express as well as Blank nodeJs App to do it
Looks like it's caused by an invalid node version on Azure. Go to Azure portal, your Web App - Application settings, check WEBSITE_NODE_DEFAULT_VERSION.
Once we specify a version not available on Azure, a quite old version 0.10.40 is in use, where const is not enabled by default so that we met SyntaxError: Use of const in strict mode. See related thread for more details.
We can use 10.6.0, 8.11.1, etc. Go to https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime to see all versions available.
Caveat by Clinkz
In some cases, the above solution may not work. This may be because your project includes the file iisnode.yml. If this file exists, it overrides application settings environment variable. The content of this file should be as follows :
nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\0.10.4\node.exe"
The node version specified here takes precendence. To fix it, simply update the version, like so and deploy:
nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\8.9.4\node.exe"
Refer to this.
To conclude, the priority: iisnode.yml > package.json(engine)> Application settings. Application setting is recommended as it's easy to check and modify on portal.
Related
I have an AWS EC2 instance for my Next.js website. If I open the terminal on my Next.js app and run next start it runs fine and I can visit the website. However, I then need to always keep the terminal open on the instance for the website to work.
My question is, can I use IIS to keep a Next.js website running with next start? I don't want to create a full node backend to serve static html pages because it will mess up some of the dynamic aspects of the website. So is there a way to run a Next.js app by itself without running next export for the static pages?
UPDATE
I attempted to run the Next.js app with PM2 instead. When I run npm start in the terminal it works fine. However, when I run pm2 start npm -- start (or any variation of that), it stops the server and logs this error multiple times:
SyntaxError: Unexpected token ':'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
:: Created by npm, please don't edit manually.
You can use forever to run your process in the backend, the below example is how to implement it with iis
https://www.technoapple.com/blog/post/run-node-as-background-by-using-forever
I'm deploying my nuxt app on planethoster who use Passenger to run Node.js Application. I build the app by using ">npm run build" and deployed the content off .nuxt folder on the server, with "server.js" as entrypoint. but I ran on the following error:
/home/scalcmjx/test.scalomhouseplans.com/server.js:1
import Vue from 'vue'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at Module.require (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at require (internal/modules/cjs/helpers.js:74:18)
at loadApplication (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:214:2)
Please Someone know how to manage it?
What is your node.js version? Try using the current LTS: 14.17.0
If I'm not mistaken, the import syntax is officially supported since v14, so this should maybe fix one issue.
Also, you need to deploy dist and not .nuxt, the latter is used for caching purposes.
I'm not sure of what is the process for this specific host, but you should probably get some decent ideas from the deployment section of the official documentation: https://nuxtjs.org/docs/2.x/deployment/deploying-to-21yunbox
There are a lot of hosting solutions there, one is probably looking like Planethoster.
We're a small team of developers and we want to develop a RESTful API service for our project. We would like to use Visual Studio for our Node.js Loopback framework development and we want to use git on VSTS for our version control. We found out that there are ways to automate build and deployment on VSTS to Azure Web app, but we're having problems creating a loopback project, creating a Visual Studio solution, and making all these work on Azure. We tried to get some help from this repository but this is not exactly how we plan to work How should we proceed?
So, we have tried creating a "Basic Azure Node.js Web Application" on Visual Studio and adding loopback to it but when we deploy this, we get "The page cannot be displayed because an internal server error has occurred." error on our page. Also we created an app.js file on the root of the project to make it point like so
var app = require('./server/server.js');
app.start();
and when we look at the logs, we see this error;
Application has thrown an uncaught exception and is terminated:
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:434:25)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\server\server.js:3:16)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
What I think might be the problem is that we can't quite figure out how to make a loopback project in Visual Studio and also how to deploy it so that it runs on our server.
I’ve deployed a small node.js app that runs fine locally in visual studio 2015 to Azure using the Azure publish option (right click – publish – azure profile etc.).
However, when I visit the site all I get on the page is:
The page cannot be displayed because an internal server error has
occurred.
If I connect VS server explorer up to the Azure instance to view the logs, inside logging-errors.txt I can see the following logged lots of times:
Wed Jul 29 2015 12:22:36 GMT+0000 (Coordinated Universal Time): Unaught exception: Error: Cannot find module 'ms'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\debug\debug.js:14:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
This is a brand new web app provisioned via the preview portal.
There is no ‘ms’ package defined either in my project dependencies or in the node_modules folder, so I'm assuming this is a Microsoft/Azure specific package required for hosting on Azure.
Have I missed a step in “preparing” my node app for Azure, or is there some other configuarion step I need to perform?
Thanks
It looks like it's having trouble loading modules. Do you have a package.json file that defines your dependencies? The default deployment script that Azure runs when you deploy your site will look for a package.json and perform an npm install --production. That means it will install everything you've defined as in 'dependencies' but not the packages you've defined as 'devDependencies'.
To debug node apps deployed to Azure that won't startup I do:
Open a Powershell on it's scm (https://.scm.azurewebsites.net/DebugConsole/?shell=powershell)
Check your node is set correctly node --version
Attempt to start it and look at errors node .\server.js (or whatever is specified in your package.json > start script.
It would be nice if you could see such a log for when Azure starts the app. However I have not found it.
Please, help me How can i solve this problem?
Starting static webserver: /home/ubuntu/node/node_modules/express/lib/express.js:89
throw new Error('Most middleware (like ' + name + ') is no longer bundle
^
Error: Most middleware (like cookieParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
at Function.Object.defineProperty.get (/home/ubuntu/node/node_modules/express/lib/express.js:89:13)
at Object.<anonymous> (/home/ubuntu/node/static-app.js:26:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:124:16)
at node.js:811:3
You have updated your express to 4.0, but it doesn't have all the middleware included now, so you have to install them manually.
See the Moving to Express 4.0 guide
Express 4 no longer depends on Connect, and removes all the built-in middleware from its core, except express.static. This means Express is now an independent routing and middleware web framework, and Express versioning and releases are not affected by middleware updates.
With the built-in middleware gone, you must explicitly add all the middleware required to run your app. Simply follow these steps:
Install the module: npm install --save
In your app, require the module: require('module-name');
Use the module according to its documentation: app.use( ... );