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.

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import

See original GitHub issue

Version

@nuxtjs/firebase: 7.5.0 --> firebase: ex: 8.10.0 nuxt: 2.15.8

macOS Big Sur

Reproduction Link

Cannot share publicly but can give access in private

Steps to reproduce

npm run generate

What is Expected?

Having an “npm run generate” working

What is actually happening?

x Nuxt Fatal Error                                                          
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import'/Users/phil/Documents/GitHub/project/node_modules/firebase/app' 
is not supported resolving ES modules imported from /Users/phil/Documents/GitHub/project/node_modules/@nuxtjs/firebase/lib/module.js
Did you mean to import 
/Users/phil/Documents/GitHub/project/node_modules/firebase/app/dist/index.cjs.js?  

I found this solution but i have no idea how to apply it to a Nuxt project

I tried many different versions of @nuxtjs/firebase & firebase, but issue always remain,

Can anyone help?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lupascommented, Nov 30, 2021

Thanks guys, fixed it with v8.1.0.

Unfortunately, the terminateDatabasesInGenerateHooks() function doesn’t seem to do its job anymore since v8. The warning "The command ‘nuxt generate’ finished but did not exit after 5s" this function was supposed to fix appears again. 😕

Screenshot 2021-11-30 at 07 28 09

But that’s not a biggie, for Nuxt v3 I’ll have to re-write the module anyway… 😃

Thanks a lot!

1reaction
mandalornlcommented, Nov 26, 2021

@randomnessdev @lupas changing the import to firebase/compat/app, instead of the absolute path seems to work. You can use the patch below, if you’d like.

diff --git a/node_modules/@nuxtjs/firebase/lib/module.js b/node_modules/@nuxtjs/firebase/lib/module.js
index d3aa31f..9f5eb34 100644
--- a/node_modules/@nuxtjs/firebase/lib/module.js
+++ b/node_modules/@nuxtjs/firebase/lib/module.js
@@ -326,9 +326,10 @@ function validateConfigKeys(options, currentEnv) {
  * See https://github.com/nuxt-community/firebase-module/issues/93
  */
 function terminateDatabasesInGenerateHooks(ctx) {
-  const firebaseDir = ctx.nuxt.options.srcDir + '/node_modules/firebase/'
   ctx.nuxt.hook('generate:before', async (generator) => {
-    const { default: firebase } = await import(firebaseDir + 'app')
+    const { default: firebase } = await import('firebase/compat/app')
+    await import('firebase/compat/database')
+    await import('firebase/compat/firestore')
 
     if (!firebase.apps.length) {
       firebase.initializeApp(generator.options.firebase.config)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Directory import when attempting to start Nodejs App ...
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import when attempting to start Nodejs App locally ; from 'cors' ; from 'express' ; from './models' ...
Read more >
Error [ERR_UNSUPPORTED_DIR_IMPORT] in Node.js
The "Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import is not supported" occurs in Node.js, when we try to use a directory import. To solve the error, ......
Read more >
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory ...
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import is not supported resolving ES modules #34439. Unanswered. perevezencev asked this question in Help.
Read more >
Directory import when attempting to start Nodejs App ...
Coding example for the question Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import when attempting to start Nodejs App locally-sequelize.js.
Read more >
ES Modules in Node.js - Maxim Orlov
Importing and exporting a module in Common JS (CJS), a.k.a. the old way: ... a-folder'; // ❌ Error [ERR_UNSUPPORTED_DIR_IMPORT] // a-folder // |...
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