如何解决在使用 Phusion Passenger V. 5.3.5 的 PLESK ONYX 服务器上部署 node.js 应用程序时出错
我想在 PLESK-ONYX 服务器上部署一个小型 node.js 应用程序 - Phusion_Passenger / 5.3.5 也在该服务器上运行!
发生以下情况:
此处有效:
var express = require ('express');
var bodyParser = require ('body-parser');
这不起作用:
import express from 'express';
import bodyParser from 'body-parser';
然后出现以下错误:
Phusion Passenger 应用程序服务器尝试通过称为“包装器”的Passenger 内部帮助工具启动Web 应用程序。但是Passenger 无法执行该辅助工具,因为它遇到了内部错误。
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';
^^^^^^^
如何解决?
问题出在哪里?
提前感谢您的帮助!
最好的问候
马库斯
你好,我在此期间有新发现......
我的问题似乎是 - 目前 PLESK 中可用的最高 node.js 版本是 12.4!
在 PLESK - 我必须用 server.js-File 启动 node.js-App - 像这样:
const app = require('./index.mjs');
const http = require('http');
http.createServer(app).listen(process.env.PORT);
我的 node.js 版本是 V.12.4,所以我必须像这样使用 esm:
require = require("esm")(module/*,options*/)
module.exports = require("./index.js")
如何以正确的方式组合这两个文件?
非常感谢您的帮助!
这里是“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"
}
}
但不幸的是我还没有找到 - 在 PLESK 中可以编辑 node.js 的启动命令!
最好的问候
马库斯
解决方法
要使用 import
from
,您应该将 package.json 中的类型更改为 module
,因此将此代码添加到 package.json
"type": "module"
注意:但导出文件在 commonjs
和 module
之间是不同的。
默认类型是 commonjs
,检查这个 article
你也可以使用 babel 模块,像这样更新 package.json 中的脚本
"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"
}
之后用于运行项目
npm start
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。