2

I want to deploy a small node.js app on a PLESK-ONYX server - on which Phusion_Passenger / 5.3.5 is also running!

The following happens:

This works here:

var express = require ('express');

var bodyParser = require ('body-parser');

That does not work:

import express from 'express';

import bodyParser from 'body-parser';

The following error then occurs:

The Phusion Passenger application server tried to start the web application through a Passenger-internal helper tool called the "wrapper". But Passenger was unable to execute that helper tool because it encountered an internal error.

The stdout/stderr output of the subprocess so far is:

/var/www/vhosts/hosting13.netcup.net/mem3-s3.hxxx-3.de/index.js:2

import express from 'express';

    ^^^^^^^

How can one solve it?

Where is the problem?

Thank you for your help in advance!

Best regards

Markus


Hello, I have new findings in the meantime ...

my problem seems to be - that the highest-available node.js version in PLESK at the moment is 12.4!

In PLESK - i must start the node.js-App with a server.js-File - like this:

const app = require('./index.mjs');
const http = require('http');

http.createServer(app).listen(process.env.PORT);

My node.js-Version is V.12.4 so i must use esm like this:

require = require("esm")(module/*, options*/)
module.exports = require("./index.js")

How can i combine the 2 files in the right way?

Thanks a lot for your help!

Here is the content of "package.json":

{
  "name": "mb-test-1",
  "version": "1.0.0",
  "description": "",
  "main": "index.mjs",
  "type": "module",
  "scripts": {
    "start": "nodemon -r esm index.mjs"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv":"^8.2.0",
    "esm":"^3.2.25",
    "express":"^4.17.1",
    "mongoose":"^5.9.29",
    "nodemon":"^2.0.7"
  }

}

But unfortunately I haven't found yet - where in PLESK the start command for node.js can be edited!

Best regards

Markus

mbulm1
  • 21
  • 5

1 Answers1

0

for using import from you should change type in package.json to module so add this code to the package.json

"type": "module"

Note: but export file is different between commonjs and module.

by default type is commonjs , check this article

you can also using babel module, update scripts in package.json like this

  "scripts": {
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "start": "npm run build && node dist/app.js"
  }

after that for running project

npm start
Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39