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.

Exports is not defined in ES module scope

See original GitHub issue

Environment


  • Operating System: Windows_NT - Windows 10 Pro, Version 21H1 (OS Build 19043.1288), WFEP 120.2212.3920.0
  • Node Version: v16.11.1
  • Nuxt Version: 3.0.0-27248715.54549cf
  • Package Manager: Yarn
  • Bundler: Vite
  • User Config: srcDir, ssr
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

When using a third-party src folder (which is not the current folder) and when server rendering is enabled, an error 500 appears - exports is not defined in ES module scope

Reproduction

  1. run npx nuxi init and yarn install
  2. create src dir and second app.vue for example (or pages/index.vue)
  3. run yarn dev

I couldn’t change the node js version on stackblitz and codesandbox, so I’m attaching my git repo for example https://github.com/eakhadov/nuxt3-bug

Additional context

srcDir: './src', ssr: true = error srcDir: './src', ssr: false = ok

srcDir: '.', ssr: true = ok srcDir: '.', ssr: false = ok

Logs

Nuxt CLI v3.0.0-27248715.54549cf                                                                                                                              00:19:35  
                                                                                                                                                              00:19:35  
  > Local:    http://localhost:3000/
  > Network:  http://192.168.208.1:3000/
  > Network:  http://172.24.112.1:3000/
  > Network:  http://192.168.1.3:3000/
  > Network:  http://172.18.192.1:3000/

√ Generated nuxt.d.ts                                                                                                                                         00:19:41
i Vite warmed up in 1334ms                                                                                                                                    00:19:42
√ Vite server built in 2178ms                                                                                                                                 00:19:43
√ Nitro built in 288 ms                                                                                                                                       00:19:43
exports is not defined in ES module scope
  at $id_29efbadd (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:88:23)
  at __instantiateModule__ (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8279:9)  
  at __ssrLoadModule__ (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8227:25)     
  at ssrImport (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8251:13)
  at $id_0a51e162 (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:15:37)
  at __instantiateModule__ (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8279:9)  
  at __ssrLoadModule__ (file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8227:25)     
  at file:///C:/Users/Emil/Desktop/nuxt-err/.nuxt/dist/server/server.mjs:8292:22
  at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
  at async Loader.import (node:internal/modules/esm/loader:178:24)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
TheLearneercommented, Nov 2, 2021

@pi0 @danielroe It seems this issue was closed but this issue still persists on latest commit as of writing this i.e. ^3.0.0-27264278.aba2d22

And like mentioned above setting ssr to false solves it, but if ssr is true this error shows up

2reactions
inluxccommented, Oct 27, 2021

Its happing to me in Mac BigSur


 WARN  [SSR] Error transforming ./node_modules/vue/server-renderer/index.js: Error: Missing "./server-renderer/index.js" export in "vue" package                                                                         12:47:48

✔ Vite server built in 1295ms                                                                                                                                                                                            12:47:48
✔ Nitro built in 169 ms                                                                                                                                                                                                  12:47:48
exports is not defined in ES module scope
  at $id_60f0615f (file://./.nuxt/dist/server/server.mjs:88:23)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at ssrImport (file://./.nuxt/dist/server/server.mjs:7166:13)
  at $id_15c79d3d (file://./.nuxt/dist/server/server.mjs:15:37)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at file://./.nuxt/dist/server/server.mjs:7207:22
  at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
  at async Loader.import (internal/modules/esm/loader.js:177:24)
exports is not defined in ES module scope
  at $id_60f0615f (file://./.nuxt/dist/server/server.mjs:88:23)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at ssrImport (file://./.nuxt/dist/server/server.mjs:7166:13)
  at $id_15c79d3d (file://./.nuxt/dist/server/server.mjs:15:37)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at file://./.nuxt/dist/server/server.mjs:7207:22
  at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
  at async Loader.import (internal/modules/esm/loader.js:177:24)
exports is not defined in ES module scope
  at $id_60f0615f (file://./.nuxt/dist/server/server.mjs:88:23)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at ssrImport (file://./.nuxt/dist/server/server.mjs:7166:13)
  at $id_15c79d3d (file://./.nuxt/dist/server/server.mjs:15:37)
  at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:7194:9)
  at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:7141:25)
  at file://./.nuxt/dist/server/server.mjs:7207:22
  at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
  at async Loader.import (internal/modules/esm/loader.js:177:24)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript ReferenceError: exports is not defined
I had the error "exports is not defined" coming from an imported NPM module. Changing my typescript config did nothing as I had...
Read more >
ReferenceError: exports is not defined in TypeScript | bobbyhadz
To solve the "Uncaught ReferenceError: exports is not defined", add a script tag that defines an exports variable, e.g. <script>var exports = {};</script>...
Read more >
ReferenceError: exports is not defined in ES module scope
Node version: 18. I'm trying to run my project with: node dist/index.js. My tsconfig.json "lib": ["ES5"]. "module": "CommonJS".
Read more >
How to fix ReferenceError: exports is not defined TypeScript
If you are getting the error for code that runs in the browser, try defining a global exports variable above the script tags...
Read more >
ReferenceError: exports is not defined in ES module scope in ...
ReferenceError : exports is not defined in ES module scope This file is being treated as an ES module because it has a...
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