![](/img/trans.png)
[英]Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/got/dist/source/index.js from /app/commands/Image/meme.js not supported
[英]Error: Must use import to load ES Module: D:\node_modules\react-markdown\index.js require() of ES modules is not supported
目前我正在使用"react": "17.0.2"
并且我已经通过 npm 安装了"react-markdown": "^7.0.1"
npm i react-markdown
我正在使用这个包来显示我的富文本m 从我的 Strapi CMS 中获取。 我使用以下代码来显示内容:
import ReactMarkdown from "react-markdown";
export default function name({ posts }) {
return (
<>
<div>
<div>
{posts.Title}
</div>
</div>
<div>
<ReactMarkdown source={posts.Content} escapeHtml={false} />
</div>
</>
);
}
export async function getStaticProps() {
const res = await fetch("http://localhost:1337/blogs");
const posts = await res.json();
return {
props: { posts },
};
}
但是当我运行它时,它给了我以下错误:
我正在使用节点v14.17.0
并尝试添加"type": "module"
。
我的 package.json:
{
"name": "passportlegacy",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"axios": "^0.21.1",
"babel-plugin-inline-react-svg": "^2.0.1",
"next": "11.0.1",
"next-images": "^1.8.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-map-gl": "^6.1.16",
"react-markdown": "^7.0.1",
},
"devDependencies": {
"@svgr/webpack": "^5.5.0",
"@types/react": "17.0.16",
"eslint": "7.32.0",
"eslint-config-next": "11.0.1",
"typescript": "4.3.5"
}
}
Node 当前将您的
.js<\/code>文件视为 CommonJS。
您需要告诉 Node 将其视为 ES 模块。
尝试在
package.json<\/code>文件中添加
"type": "module"<\/code> 。
您可以将其放置在顶层的任何位置。 例如:
{
"name": "passportlegacy",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
...
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.