question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prerender issue: ERROR [nuxt] [request error] exports is not defined in ES module scope

See original GitHub issue

Environment

Nuxt CLI v3.0.0-rc.4 19:44:27 RootDir: /home/user/workspace/nuxt3-multi-page 19:44:28 Nuxt project info: 19:44:28


  • Operating System: Linux
  • Node Version: v16.15.1
  • Nuxt Version: 3.0.0-rc.4
  • Package Manager: yarn@3.2.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

👉 Report an issue: https://github.com/nuxt/framework/issues/new 19:44:28

👉 Suggest an improvement: https://github.com/nuxt/framework/discussions/new

👉 Read documentation: https://v3.nuxtjs.org

Reproduction

import {defineNuxtConfig} from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  preset: "netlify",
  ssr: false,
  nitro: {
    prerender: {
      routes: [
        '/blog'
      ]
    }
  },
  modules: [
    '@nuxtjs/tailwindcss'
  ]
})

Hint: tried it with ssr: true and false

sample component:

<template>
  <fetch-method-layout name="useLazyFetch()">
      <ul>
        <li v-for="post in posts">{{ post.name }}</li>
      </ul>
  </fetch-method-layout>
</template>

<script setup>

import FetchMethodLayout from "../layouts/FetchMethodLayout";

const {data: posts, pending, error, refresh} = useLazyFetch('/api/posts')

</script>

<style scoped>

</style>

posts.get.ts

// @ts-ignore
export default defineEventHandler((event) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        posts: [
          {
            "name": "First Post"
          },
          {
            "name": "Second Post"
          },
          {
            "name": "Third Post"
          }
        ]
      })
    }, 0)
  })
})

Describe the bug

Can’t run nuxi build, generate or serve anymore without errors.

Cannot make any sense of the exceptions.

The API is working when I call it directly, the pages are not

Additional context

No response

Logs

> nuxi build 

produces


Nuxt CLI v3.0.0-rc.4                                                                                                                                                                                                          19:47:02
ℹ Using default Tailwind CSS file from runtime/tailwind.css                                                                                                                                                  nuxt:tailwindcss 19:47:06
ℹ Merging Tailwind config from ~/tailwind.config.js                                                                                                                                                          nuxt:tailwindcss 19:47:06
ℹ Vite client warmed up in 3437ms                                                                                                                                                                                             19:47:11
ℹ Client built in 5178ms                                                                                                                                                                                                      19:47:13
ℹ Building server...                                                                                                                                                                                                          19:47:13
✔ Server built in 2063ms                                                                                                                                                                                                      19:47:15
✔ Generated public .output/public                                                                                                                                                                                       nitro 19:47:15
ℹ Initializing prerenderer                                                                                                                                                                                              nitro 19:47:15
ℹ Prerendering 1 routes                                                                                                                                                                                                 nitro 19:47:20

 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)


 ERROR  [nuxt] [request error] exports is not defined in ES module scope                                                                                                                                                      19:47:20  
  at ./.nuxt/prerender/chunks/app/server.mjs:4109:1
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async ./.nuxt/prerender/chunks/renderer.mjs:11160:24
  at async ./.nuxt/prerender/chunks/renderer.mjs:11215:64
  at async /home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:420:19
  at async nodeHandler (/home/user/workspace/nuxt3-multi-page/node_modules/h3/dist/index.mjs:370:7)
  at async ufetch (/home/user/workspace/nuxt3-multi-page/node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async generateRoute (/home/user/workspace/nuxt3-multi-page/node_modules/nitropack/dist/chunks/prerender.mjs:2301:17)

while

nuxi serve

produces

[nuxt] [request error] Cannot set properties of undefined (setting '__esModule')
  at $id_5ed6902a (./.nuxt/dist/server/server.mjs:3154:20)
  at __instantiateModule__ (./.nuxt/dist/server/server.mjs:5326:9)
  at __ssrLoadModule__ (./.nuxt/dist/server/server.mjs:5264:25)
  at ssrImport (./.nuxt/dist/server/server.mjs:5289:13)
  at $id_16657e2a (./.nuxt/dist/server/server.mjs:3046:38)
  at async __instantiateModule__ (./.nuxt/dist/server/server.mjs:5326:3)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mkluehcommented, Jul 21, 2022

@danielroe I haven’t faced this issue anymore since then and couldn’t reproduce it anymore. I had this issue as well https://github.com/dependabot/dependabot-core/issues/1297#issuecomment-1159518380 and maybe they were related somehow.

In case I’ll see it again, I’ll come back to this issue

0reactions
danielroecommented, Jul 21, 2022

Would you provide a reproduction if you are still encountering this? 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

exports is not defined in ES module scope - Stack Overflow
It gives me below error. Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module c:\project\node_modules\@nuxt\vite-builder-edge\dist\ ...
Read more >
How to fix ReferenceError: exports is not defined TypeScript
This will define the exports variable and set it to an empty object, so you don't get an error if properties are accessed...
Read more >
How to solve "window is not defined" errors in React and Next.js
Second solution: the useEffect hook. The "React" way to solve this issue would be to use the useEffect React hook. Which only runs...
Read more >
exports is not defined in es module scope lambda - You.com
exports is not defined in ES module scope - the reason for this error is that Node.js 18.x runtime is using ECMAScript modules...
Read more >
Server-Side Rendering (SSR) - Vue.js
Synchronous being the key word there. If your app starts with a loading spinner, then fetches content via Ajax, the crawler will not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found