-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Hello:
In Lesson 190, once I add the line of code:
const postData = getPostData(slug);
Immediately I'm getting an 'ERR_REQUIRE_ESM' that keeps looping in the terminal. I have copied the code from [slug].js and posts-util.js from your nextjs-course-code on github into my project to make sure I didn't code something wrong and I'm still getting this looping error in the terminal. This is what the error looks like:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\NextJS_Work\nextjs-course-code-full-blog\node_modules\react-markdown\index.js
require() of ES modules is not supported.
require() of C:\NextJS_Work\nextjs-course-code-full-blog\node_modules\react-markdown\index.js from C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\NextJS_Work\nextjs-course-code-full-blog\node_modules\react-markdown\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.react-markdown (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:1157:18)
at webpack_require (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:23:31)
at Module../component/posts/post-detail/post-content.js (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:140:72)
at webpack_require (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:23:31)
at Module../pages/posts/[slug].js (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:1020:99)
at webpack_require (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:23:31)
at C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:91:18
at Object. (C:\NextJS_Work\nextjs-course-code-full-blog.next\server\pages\posts[slug].js:94:10)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32) {
code: 'ERR_REQUIRE_ESM'
When I comment out that line of code that calls getPostData(slug) - which I know we do not want to do - the ERR_REQUIRE_ESM looping error stops but then I see this error in the terminal:
error - ./lib/posts-util.js:1:0
Module not found: Can't resolve 'fs'
1 | import fs from "fs";
I am using VS Code version 1.63.2.
I tried and I do not know how to get around this. Can you or somebody please help me with this error? I can no longer continue with this course until I can get around this issue, and I would really like to complete this course.
Thank you