NEXT.JS - Server Error: Must use import to load ES Module: C: Users ... nextjs-blog node_modules Remark index.js

Asked

Viewed 82 times

0

Guys, I followed the tutorial of the official website of Next.js in this link ( https://nextjs.org/learn/basics/dynamic-routes/render-markdown ) and I got the following error: "Server Error Error: Must use import to load ES Module: C: Users Gustavo Documents VSCODE Next.js Next.js Tutorial nextjs-blog node_modules Remark index.js require() of ES modules is not supported. require() of C: Users Gustavo Documents VSCODE Next.js Next.js Tutorial nextjs-blog node_modules Remark index.js from C: Users Gustavo Documents VSCODE Next.js Next.js Tutorial nextjs-blog.next server pages index.js is an ES module file as it is a . js file Whose Nearest Parent package.json contains "type": "module" which defines all . js files in that package Scope as ES modules. Instead Rename C: Users Gustavo Documents VSCODE Next.js Next.js Tutorial nextjs-blog node_modules Remark index.js to end in . cjs, change the requiring code to use import(), or remove "type": "module" from C: Users Gustavo Documents VSCODE Next.js Next.js Tutorial nextjs-blog node_modules Remark package.json.

This error happened while generating the page. Any console logs will be displayed in the terminal window. "

From what I understand there is some problem with the import or require commands, but I used import from start to link point without error. In this step of the link the blog stopped working.

I appreciate any help. The code is on: https://github.com/profglac/Next-blog

  • Put the piece of code to be analyzed too.

1 answer

0

I was able to figure out the problem. I updated the version of the Remark dependency from 14.0.0 to 13.0.0 and the problem was solved. Below is the final package.json file in case anyone has this problem. { "name": "Learn-Starter", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start" }, "dependencies": { "date-fns": "2.23.0", "Gray-Matter": "4.0.3", "next": "11.0.0", "React": "17.0.2", "Gift": "17.0.2", "Remark": " 13.0.0", "Remark-html": "13.0.1", "Unified": " 10.1.0" } }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.