我在运行此代码时遇到此错误。
let { controllerUser } = require('./router')
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 'C:\Project\first-project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
使用 package.json 中的类型模块在 Node js 中进行路由
如果您有:
"type":"module"
在
package.json
中,尝试使用:
import {controllerUser} from "./router.js"
不能将 ES6 模块与 CommonJS 模块混合使用。