srvpro使用node启动问题
Kkyoyo opened this issue · comments
我使用node去启动ygopro-server时,错误如下:
`/root/ygo2/ygopro-server/ygopro-server.js:77
loadJSON = require('load-json-file').sync;
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /root/ygo2/ygopro-server/node_modules/_load-json-file@7.0.1@load-json-file/index.js from /root/ygo2/ygopro-server/ygopro-server.js not supported.
Instead change the require of index.js in /root/ygo2/ygopro-server/ygopro-server.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/root/ygo2/ygopro-server/ygopro-server.js:77:14)
at Object.<anonymous> (/root/ygo2/ygopro-server/ygopro-server.js:5277:4) {
code: 'ERR_REQUIRE_ESM'
}`
根据查询是试用了load-json-file使用了es6语法而项目不支持,不知道如何解决
npm i load-json-file@6.2.0
感谢回复,解决了那个问题以后还有这个提示
`root@iZuf646y583ci0k754bvztZ:~/ygo2/ygopro-server# node ygopro-server.js
file:///root/ygo2/ygopro-server/ygopro-server.js:6
net = require('net');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/root/ygo2/ygopro-server/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///root/ygo2/ygopro-server/ygopro-server.js:6:3
at file:///root/ygo2/ygopro-server/ygopro-server.js:5277:4
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)`
系统是ubuntu20
原本的 package.json 里没有 "type": "module"
,不知道你是怎么添加的,删掉应该就好了
你的 node 运行环境是?
原本的 package.json 里没有
"type": "module"
,不知道你是怎么添加的,删掉应该就好了
感谢回复,已经可以了,"type": "module"
是因为之前那个load-json-file的问题添加的,现在去掉就行了
你的 node 运行环境是?
是16.14.0,问题已经解决了,感谢大佬们