Skip to content

Error [ERR_REQUIRE_ESM]: require() of ES Module,nstead rename .eslintrc.js to end in .cjs, change the requiring code to use dynamic import()

如果package.json文件里有"type": "module"会报错

Error [ERR_REQUIRE_ESM]: Cannot read config file: D:\webzhijProjects\院内就诊\hospitalvisit.eslintrc.js Error: require() of ES Module D:\webzhijProjects\院内就诊\hospitalvisit.eslintrc.js from D:\webzhijProjects\院内就诊\hospitalvisit\node_modules@eslint\eslintrc\dist\eslintrc.cjs not supported. .eslintrc.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 .eslintrc.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 D:\webzhijProjects\院内就诊\hospitalvisit\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Error [ERR_REQUIRE_ESM]: require() of ES Module D:\webzhijProjects\院内就诊\hospitalvisit.eslintrc.js from D:\webzhijProjects\院内就诊\hospitalvisit\node_modules@eslint\eslintrc\dist\eslintrc.cjs not supported. .eslintrc.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 .eslintrc.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 D:\webzhijProjects\院内就诊\hospitalvisit\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

解决办法:删除"type": "module"

如有转载或 CV 的请标注本站原文地址