Javascript 如何告知pm2在部署时使用特定的节点版本
编辑——在尝试使用旧版本的node(8.1.0)在我的机器上安装Puppeter之后,它抛出了相同的错误。因此,问题一定是当连接到机器时,它没有加载到正确的节点版本中。然后,问题是如何使用正确的node.js版本运行pm2后期部署挂钩? 当我尝试使用Javascript 如何告知pm2在部署时使用特定的节点版本,javascript,puppeteer,yarnpkg,package.json,pm2,Javascript,Puppeteer,Yarnpkg,Package.json,Pm2,编辑——在尝试使用旧版本的node(8.1.0)在我的机器上安装Puppeter之后,它抛出了相同的错误。因此,问题一定是当连接到机器时,它没有加载到正确的节点版本中。然后,问题是如何使用正确的node.js版本运行pm2后期部署挂钩? 当我尝试使用pm2deploy部署我的web抓取应用程序时,我遇到了一个非常奇怪的错误。错误发生在pm2部署过程的post-install钩子期间,也就是warn将各种软件包安装到我的远程机器(Ubuntu 18.04)时 错误如下所示: ....The res
pm2
deploy部署我的web抓取应用程序时,我遇到了一个非常奇怪的错误。错误发生在pm2
部署过程的post-install
钩子期间,也就是warn
将各种软件包安装到我的远程机器(Ubuntu 18.04)时
错误如下所示:
....The rest of the yarn installation...
[4/4] Building fresh packages...
error /home/harrison/gql3.0_processors/source/node_modules/puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /home/harrison/gql3.0_processors/source/node_modules/puppeteer
Output:
/home/harrison/gql3.0_processors/source/node_modules/puppeteer/install.js:175
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
post-deploy hook failed
Deploy failed
... The rest of the ecosystem.config.js file ...
deploy: {
production: {
user: "harrison",
host: hosts,
key: "~/.ssh/id_rsa",
ref: "origin/master",
repo: process.env.GIT_REPO,
path: process.env.PROJECT_PATH,
/// Source the user's .zshrc file first!!
"post-deploy": `source ~/.zshrc && \
yarn install --ignore-engines && \
yarn prod:build && \
yarn prod:serve`
}
}
这来自我的节点_modules
文件夹的puppeter
目录中的install.js
文件,这是我在项目中使用的依赖项
我倾向于认为这是由于在远程安装应用程序时节点版本出现某种错误造成的?有人能提供一些指导吗
我的pm2
部署文件如下(有关更多信息,请转到此处:)
无论出于何种原因,
pm2
部署后脚本没有加载到我的.zshrc
文件中,因此它尝试使用的Node.js版本不正确。我可以通过在安装后阶段运行printenv
命令(显示$PATH
变量不包括我的nvm
版本)看到这一点
因此,解决方案是在部署后
脚本期间专门为.zshrc
文件(或使用bash的用户的.bashrc
文件)提供源代码,如下所示:
....The rest of the yarn installation...
[4/4] Building fresh packages...
error /home/harrison/gql3.0_processors/source/node_modules/puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /home/harrison/gql3.0_processors/source/node_modules/puppeteer
Output:
/home/harrison/gql3.0_processors/source/node_modules/puppeteer/install.js:175
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
post-deploy hook failed
Deploy failed
... The rest of the ecosystem.config.js file ...
deploy: {
production: {
user: "harrison",
host: hosts,
key: "~/.ssh/id_rsa",
ref: "origin/master",
repo: process.env.GIT_REPO,
path: process.env.PROJECT_PATH,
/// Source the user's .zshrc file first!!
"post-deploy": `source ~/.zshrc && \
yarn install --ignore-engines && \
yarn prod:build && \
yarn prod:serve`
}
}
这是必要的,因为我的
.zshrc
文件是在nvm环境中加载的(并设置了我加载更高版本的节点)。该节点版本是Thread在运行安装脚本时所依赖的,这就是过时版本失败的原因。要使用节点版本更新创建的pm2应用程序,请执行以下步骤: