webnuxt 使用宝塔启动失败
webnuxt
生产环境布署

服务器上安装宝塔后部署webnuxt,启动服务时失败,在终端输入 pnpm start 运行报错:
Error [ERR_REQUIRE_ESM]: require() of ES Module /www/wwwroot/default/ecosystem.config.js from /www/server/nodejs/v18.18.2/lib/node_modules/pm2/lib/Common.js not supported. ecosystem.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename ecosystem.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /www/wwwroot/default/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

根据错误信息,可能是 ecosystem.config.js 文件被当作了 ES 模块(ECMAScript 模块)来处理,而当前环境似乎不支持使用 require() 导入 ES 模块。

解决方法:修改 package.json 中的 "type" 字段:将 "module" 改为 "commonjs",这样所有的 .js 文件都会被识别为 CommonJS 模块。

1个回答默认排序 投票数排序
pkay
pkay
这家伙很懒,什么也没写~
8月前

曾经遇到过相同的问题,最后将pnpm换回npm或者yarn解决了

不知道你是不是这种情况,可以将详细运行环境和报错信息贴一下吗?

请先登录
0
1
0
1